MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / mspace_calloc

Function mspace_calloc

libCacheSim/dataStructure/sparsepp/spp_dlalloc.h:3755–3776  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3753}
3754
3755SPP_API inline void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size)
3756{
3757 void* mem;
3758 size_t req = 0;
3759 mstate ms = (mstate)msp;
3760 if (!ms->ok_magic())
3761 {
3762 SPP_USAGE_ERROR_ACTION(ms, ms);
3763 return 0;
3764 }
3765 if (n_elements != 0)
3766 {
3767 req = n_elements * elem_size;
3768 if (((n_elements | elem_size) & ~(size_t)0xffff) &&
3769 (req / n_elements != elem_size))
3770 req = spp_max_size_t; // force downstream failure on overflow
3771 }
3772 mem = ms->internal_malloc(req);
3773 if (mem != 0 && mem2chunk(mem)->calloc_must_clear())
3774 memset(mem, 0, req);
3775 return mem;
3776}
3777
3778SPP_API inline void* mspace_realloc(mspace msp, void* oldmem, size_t bytes)
3779{

Callers

nothing calls this directly

Calls 4

mem2chunkFunction · 0.85
ok_magicMethod · 0.80
internal_mallocMethod · 0.80
calloc_must_clearMethod · 0.80

Tested by

no test coverage detected