开发者

Posix equivalent of LocalAlloc(LMEM_ZEROINIT, size)

开发者 https://www.devze.com 2023-01-03 09:49 出处:网络
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.开

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消