Sponsored Content
Full Discussion: memset vs calloc
Top Forums UNIX for Advanced & Expert Users memset vs calloc Post 302215481 by shamrock on Wednesday 16th of July 2008 11:54:26 AM
Old 07-16-2008
memset() initializes byte strings to a user supplied value that is restricted to the unsigned char range. It does not allocate any memory.

calloc() allocates memory of any type (char, int, struct) and initializes that storage to zeros.

Both initialize a given storage area [memset() being the more exclusive of the two functions] but only one allocates memory for storage of a particular object type.
 

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
XtMalloc(3)							   XT FUNCTIONS 						       XtMalloc(3)

NAME
XtMalloc, XtCalloc, XtRealloc, XtFree, XtNew, XtNewString - memory management functions SYNTAX
char *XtMalloc(Cardinal size); char *XtCalloc(Cardinal num, Cardinal size); char *XtRealloc(char *ptr, Cardinal num); void XtFree(char *ptr); type *XtNew(type); String XtNewString(String string); ARGUMENTS
num Specifies the number of bytes or array elements. ptr Specifies a pointer to the old storage or to the block of storage that is to be freed. size Specifies the size of an array element (in bytes) or the number of bytes desired. string Specifies a previously declared string. type Specifies a previously declared data type. DESCRIPTION
The XtMalloc functions returns a pointer to a block of storage of at least the specified size bytes. If there is insufficient memory to allocate the new block, XtMalloc calls XtErrorMsg. The XtCalloc function allocates space for the specified number of array elements of the specified size and initializes the space to zero. If there is insufficient memory to allocate the new block, XtCalloc calls XtErrorMsg. The XtRealloc function changes the size of a block of storage (possibly moving it). Then, it copies the old contents (or as much as will fit) into the new block and frees the old block. If there is insufficient memory to allocate the new block, XtRealloc calls XtErrorMsg. If ptr is NULL, XtRealloc allocates the new storage without copying the old contents; that is, it simply calls XtMalloc. The XtFree function returns storage and allows it to be reused. If ptr is NULL, XtFree returns immediately. XtNew returns a pointer to the allocated storage. If there is insufficient memory to allocate the new block, XtNew calls XtErrorMsg. XtNew is a convenience macro that calls XtMalloc with the following arguments specified: ((type *) XtMalloc((unsigned) sizeof(type)) XtNewString returns a pointer to the allocated storage. If there is insufficient memory to allocate the new block, XtNewString calls XtEr- rorMsg. XtNewString is a convenience macro that calls XtMalloc with the following arguments specified: (strcpy(XtMalloc((unsigned) strlen(str) + 1), str)) SEE ALSO
X Toolkit Intrinsics - C Language Interface Xlib - C Language X Interface X Version 11 libXt 1.0.5 XtMalloc(3)
All times are GMT -4. The time now is 10:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy