void
allocateExample1()
{
void* p = NULL;
int len = 10;
__try
{
p = malloc(len);
if (!p)
{
printf("[allocateExample1] : malloc failed : (%d - %s) \n", errno, strerror(errno));
__leave;
}
memset(p, 0, len);
}
__finally
{
if (p)
{
free(p);
p = NULL;
}
}
return;
}
void
allocateExample2()
{
void* p = NULL;
int len = 10;
__try
{
p = calloc(1, len);
if (!p)
{
printf("[allocateExample1] : calloc failed : (%d - %s) \n", errno, strerror(errno));
__leave;
}
}
__finally
{
if (p)
{
free(p);
p = NULL;
}
}
return;
}
malloc和calloc
最新推荐文章于 2022-09-26 11:42:01 发布