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

Method ialloc

libCacheSim/dataStructure/sparsepp/spp_dlalloc.h:3416–3541  ·  view source on GitHub ↗

Common support for independent_X routines, handling all of the combinations that can result. The opts arg has: bit 0 set if all elements are same size (using sizes[0]) bit 1 set if elements should be zeroed */

Source from the content-addressed store, hash-verified

3414 bit 1 set if elements should be zeroed
3415*/
3416void** malloc_state::ialloc(size_t n_elements, size_t* sizes, int opts,
3417 void* chunks[])
3418{
3419
3420 size_t element_size; // chunksize of each element, if all same
3421 size_t contents_size; // total size of elements
3422 size_t array_size; // request size of pointer array
3423 void* mem; // malloced aggregate space
3424 mchunkptr p; // corresponding chunk
3425 size_t remainder_size; // remaining bytes while splitting
3426 void** marray; // either "chunks" or malloced ptr array
3427 mchunkptr array_chunk; // chunk for malloced ptr array
3428 flag_t was_enabled; // to disable mmap
3429 size_t size;
3430 size_t i;
3431
3432 mparams.ensure_initialization();
3433 // compute array length, if needed
3434 if (chunks != 0)
3435 {
3436 if (n_elements == 0)
3437 return chunks; // nothing to do
3438 marray = chunks;
3439 array_size = 0;
3440 }
3441 else
3442 {
3443 // if empty req, must still return chunk representing empty array
3444 if (n_elements == 0)
3445 return (void**)internal_malloc(0);
3446 marray = 0;
3447 array_size = request2size(n_elements * (sizeof(void*)));
3448 }
3449
3450 // compute total element size
3451 if (opts & 0x1)
3452 {
3453 // all-same-size
3454 element_size = request2size(*sizes);
3455 contents_size = n_elements * element_size;
3456 }
3457 else
3458 {
3459 // add up all the sizes
3460 element_size = 0;
3461 contents_size = 0;
3462 for (i = 0; i != n_elements; ++i)
3463 contents_size += request2size(sizes[i]);
3464 }
3465
3466 size = contents_size + array_size;
3467
3468 /*
3469 Allocate the aggregate chunk. First disable direct-mmapping so
3470 malloc won't use it, since we would not be able to later
3471 free/realloc space internal to a segregated mmap region.
3472 */
3473 was_enabled = use_mmap();

Callers 2

Calls 8

request2sizeFunction · 0.85
mem2chunkFunction · 0.85
assertFunction · 0.85
chunk2memFunction · 0.85
ensure_initializationMethod · 0.80
chunksizeMethod · 0.80
is_mmappedMethod · 0.80
chunk_plus_offsetMethod · 0.80

Tested by

no test coverage detected