Posix equivalent of LocalAlloc(LMEM_ZEROINIT, size)
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?
From what I understand it just allocs zeroed memory, so a calloc(1, size)
should suffice to allocate size
zeroed bytes.
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);
}
精彩评论