void * sc_calloc (int package, size_t nmemb, size_t size) { void *ret; int *malloc_count = sc_malloc_count (package); /* allocate memory */ #if defined SC_ENABLE_MEMALIGN ret = sc_malloc_aligned (SC_MEMALIGN_BYTES, nmemb * size); memset (ret, 0, nmemb * size); #else ret = calloc (nmemb, size); if (nmemb * size > 0) { SC_CHECK_ABORTF (ret != NULL, "Allocation (calloc size %lli)", (long long int) size); } #endif /* count the allocations */ #ifdef SC_ENABLE_PTHREAD sc_package_lock (package); #endif if (nmemb * size > 0) { ++*malloc_count; } else { *malloc_count += ((ret == NULL) ? 0 : 1); } #ifdef SC_ENABLE_PTHREAD sc_package_unlock (package); #endif return ret; }
void * sc_calloc (int package, size_t nmemb, size_t size) { void *ret; int *malloc_count = sc_malloc_count (package); ret = calloc (nmemb, size); if (nmemb * size > 0) { SC_CHECK_ABORT (ret != NULL, "Allocation"); } #ifdef SC_ENABLE_PTHREAD sc_package_lock (package); #endif if (nmemb * size > 0) { ++*malloc_count; } else { *malloc_count += ((ret == NULL) ? 0 : 1); } #ifdef SC_ENABLE_PTHREAD sc_package_unlock (package); #endif return ret; }
void * sc_calloc (int package, size_t nmemb, size_t size) { void *ret; int *malloc_count = sc_malloc_count (package); ret = calloc (nmemb, size); if (nmemb * size > 0) { SC_CHECK_ABORT (ret != NULL, "Allocation"); ++*malloc_count; } else { *malloc_count += ((ret == NULL) ? 0 : 1); } return ret; }
void * sc_calloc (int package, size_t nmemb, size_t size) { void *ret; int *malloc_count = sc_malloc_count (package); #ifdef SC_ALLOC_ALIGN size_t aligned; if (size == 0) { return NULL; } nmemb += (sc_page_bytes + size - 1) / size; #endif ret = calloc (nmemb, size); if (nmemb * size > 0) { SC_CHECK_ABORT (ret != NULL, "Allocation"); ++*malloc_count; } else { *malloc_count += ((ret == NULL) ? 0 : 1); } #ifdef SC_ALLOC_PAGE aligned = (((size_t) ret + sizeof (size_t) + sc_page_bytes - 1) / sc_page_bytes) * sc_page_bytes; #endif #ifdef SC_ALLOC_LINE aligned = (((size_t) ret + sizeof (size_t) + sc_page_bytes - sc_line_no * sc_line_bytes - 1) / sc_page_bytes) * sc_page_bytes + sc_line_no * sc_line_bytes; sc_line_no = (sc_line_no + 1) % sc_line_count; #endif #ifdef SC_ALLOC_ALIGN SC_ASSERT (aligned >= (size_t) ret + sizeof (size_t)); SC_ASSERT (aligned <= (size_t) ret + sc_page_bytes); ((size_t *) aligned)[-1] = (size_t) ret; ret = (void *) aligned; #endif return ret; }