Adjust hcmalloc to be the same as calloc

calloc is almost equivalent to malloc + memset(0) except that it's faster with big allocations because of OS trickery. It also protects against integer overflow and throws a null pointer on overflow whereas malloc does not.
pull/1379/head
neheb 7 years ago committed by Rosen Penev
parent 822ae7b9a9
commit baeb51ad38

@ -23,16 +23,8 @@ void *hccalloc (const size_t nmemb, const size_t sz)
void *hcmalloc (const size_t sz)
{
void *p = malloc (sz);
if (p == NULL)
{
fprintf (stderr, "%s\n", MSG_ENOMEM);
return (NULL);
}
memset (p, 0, sz);
//calloc is faster than malloc with big allocations, so just use that.
void *p = hccalloc (sz, 1);
return (p);
}

Loading…
Cancel
Save