tags:

views:

61

answers:

2

I have code which works on windows, that calls LocalAlloc as follows:

LocalAlloc(LMEM_ZEROINIT, size)

I need the equivalent malloc or calloc call to get this to work on Unix systems, through Mono. Simple answer?

+3  A: 

From what I understand it just allocs zeroed memory, so a calloc(1, size) should suffice to allocate size zeroed bytes.

cjg
A: 

I thought LocalAlloc was deprecated in favor of HeapAlloc?

Either way calloc(), malloc() and realloc(), free() are the POSIX choices for memory management.

You always check the return value:

char *retval=calloc(1, sizeof(object type) );
if(retval==NULL)
{
   perror("Memory error");
   exit(EXIT_FAILURE);
}
jim mcnamara