Sponsored Content
Full Discussion: memset vs calloc
Top Forums UNIX for Advanced & Expert Users memset vs calloc Post 302215344 by zaxxon on Wednesday 16th of July 2008 06:10:13 AM
Old 07-16-2008
Uh oh... best being moved/posted in High level programming subforum next door I guess (if no answer comes).
 

8 More Discussions You Might Find Interesting

1. Programming

about memset fuction

Dear all, In my code,i am planning to use memset function to re-initialise an array before populating it everytime. Will using memset function be an overload to the program? (3 Replies)
Discussion started by: ranj@chn
3 Replies

2. UNIX for Dummies Questions & Answers

questions in memset

HI all , please find the piece of code below char *t; char *f; char buf; memset(buf,0,50); after that i am assigning memory for (i=0; i<100; i++) { t = buf+(i*6); f = "ARUN"; } my question .. 1) i have run this it is... (7 Replies)
Discussion started by: arunkumar_mca
7 Replies

3. Solaris

application Crashes on memset ?? any suggestions

Hi All, we have an application that is written in 'C' programming to connects to various servers in the organization. The bellow code establish a TCP connection to connect to the remote servers. the application works perfectly ok, but, after some time the entire process get's crashed and... (2 Replies)
Discussion started by: sudharma
2 Replies

4. Programming

C bzero() to memset() issue

Hi guys, my tool works fine in gentoo, ubuntu now im trying to port it to windows but bzero/bcopy I read aren't working on windows and for better portability I should of use memset() so im trying to translate bzero(buffer,256);in printf("MAIL TO"); strcpy(buffer, rcp); ... (4 Replies)
Discussion started by: Jess83
4 Replies

5. Programming

Calloc C++

Hello all, I have a confusion with calloc function : wz. the difference between the following 2 statemnts: char *ptr; char = (char*)calloc(num, sizeof(char)); char = (char*)calloc(num, sizeof(char*)); Am really confused!!!!! ---------- Post updated at 09:32 AM... (1 Reply)
Discussion started by: mind@work
1 Replies

6. Programming

Iterating and calloc questions.

Whilst creating the function readjust_descr I have stumble across what may be a problem or something that might just work. I was hoping someone could look at the code below and tell me if readjust_descr will clear all null pointers from the structure descr_list. struct descr descr_list =... (6 Replies)
Discussion started by: Errigour
6 Replies

7. Programming

calloc fails: 'Cannot allocate memory'

Hi , experts. I work on Linux station (RedHat 5.7), regular user, but have root password. %> uname -a Linux ran1log06 2.6.18-238.1.1.el5 #1 SMP Tue Jan 4 13:32:19 EST 2011 x86_64 x86_64 x86_64 GNU/Linux %> cat /etc/issue Red Hat Enterprise Linux Client release 5.7 (Tikanga) Kernel \r on... (5 Replies)
Discussion started by: baruchgu
5 Replies

8. Emergency UNIX and Linux Support

Memset fails on Solaris

Hi, memset call is failing on solaris for me. I wrote below code and that also fails. Any hints? void *memset(void *dst, int c, size_t n) { if (n) { char *d = dst; do { *d++ = c; } while (--n); } return dst; } (2 Replies)
Discussion started by: skyineyes
2 Replies
explain_calloc(3)					     Library Functions Manual						 explain_calloc(3)

NAME
explain_calloc - explain calloc(3) errors SYNOPSIS
#include <libexplain/calloc.h> const char *explain_calloc(size_t nmemb, size_t size); const char *explain_errno_calloc(int errnum, size_t nmemb, size_t size); void explain_message_calloc(char *message, int message_size, size_t nmemb, size_t size); void explain_message_errno_calloc(char *message, int message_size, int errnum, size_t nmemb, size_t size); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the calloc(3) system call. explain_calloc const char *explain_calloc(size_t nmemb, size_t size); The explain_calloc function is used to obtain an explanation of an error returned by the calloc(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. nmemb The original nmemb, exactly as passed to the calloc(3) system call. size The original size, exactly as passed to the calloc(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: errno = 0; void *result = calloc(nmemb, size); if (!result && errno != 0) { fprintf(stderr, "%s ", explain_calloc(nmemb, size)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_calloc_or_die(3) function. explain_errno_calloc const char *explain_errno_calloc(int errnum, size_t nmemb, size_t size); The explain_errno_calloc function is used to obtain an explanation of an error returned by the calloc(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. nmemb The original nmemb, exactly as passed to the calloc(3) system call. size The original size, exactly as passed to the calloc(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: errno = 0; void *result = calloc(nmemb, size); if (!result && errno != 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_calloc(err, nmemb, size)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_calloc_or_die(3) function. explain_message_calloc void explain_message_calloc(char *message, int message_size, size_t nmemb, size_t size); The explain_message_calloc function is used to obtain an explanation of an error returned by the calloc(3) system call. The least the mes- sage will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. nmemb The original nmemb, exactly as passed to the calloc(3) system call. size The original size, exactly as passed to the calloc(3) system call. Example: This function is intended to be used in a fashion similar to the following example: errno = 0; void *result = calloc(nmemb, size); if (!result && errno != 0) { char message[3000]; explain_message_calloc(message, sizeof(message), nmemb, size); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_calloc_or_die(3) function. explain_message_errno_calloc void explain_message_errno_calloc(char *message, int message_size, int errnum, size_t nmemb, size_t size); The explain_message_errno_calloc function is used to obtain an explanation of an error returned by the calloc(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. nmemb The original nmemb, exactly as passed to the calloc(3) system call. size The original size, exactly as passed to the calloc(3) system call. Example: This function is intended to be used in a fashion similar to the following example: errno = 0; void *result = calloc(nmemb, size); if (!result && errno != 0) { int err = errno; char message[3000]; explain_message_errno_calloc(message, sizeof(message), err, nmemb, size); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_calloc_or_die(3) function. SEE ALSO
calloc(3) Allocate and clear memory explain_calloc_or_die(3) Allocate and clear memory and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2010 Peter Miller explain_calloc(3)
All times are GMT -4. The time now is 04:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy