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

Method prepend_alloc

libCacheSim/dataStructure/sparsepp/spp_dlalloc.h:2439–2482  ·  view source on GitHub ↗

Allocate chunk and prepend remainder with chunk in successor base. */

Source from the content-addressed store, hash-verified

2437
2438/* Allocate chunk and prepend remainder with chunk in successor base. */
2439void* malloc_state::prepend_alloc(char* newbase, char* oldbase, size_t nb)
2440{
2441 mchunkptr p = align_as_chunk(newbase);
2442 mchunkptr oldfirst = align_as_chunk(oldbase);
2443 size_t psize = (char*)oldfirst - (char*)p;
2444 mchunkptr q = (mchunkptr)p->chunk_plus_offset(nb);
2445 size_t qsize = psize - nb;
2446 set_size_and_pinuse_of_inuse_chunk(p, nb);
2447
2448 assert((char*)oldfirst > (char*)q);
2449 assert(oldfirst->pinuse());
2450 assert(qsize >= MIN_CHUNK_SIZE);
2451
2452 // consolidate remainder with first chunk of old base
2453 if (oldfirst == _top)
2454 {
2455 size_t tsize = _topsize += qsize;
2456 _top = q;
2457 q->_head = tsize | PINUSE_BIT;
2458 check_top_chunk(q);
2459 }
2460 else if (oldfirst == _dv)
2461 {
2462 size_t dsize = _dvsize += qsize;
2463 _dv = q;
2464 q->set_size_and_pinuse_of_free_chunk(dsize);
2465 }
2466 else
2467 {
2468 if (!oldfirst->is_inuse())
2469 {
2470 size_t nsize = oldfirst->chunksize();
2471 unlink_chunk(oldfirst, nsize);
2472 oldfirst = (mchunkptr)oldfirst->chunk_plus_offset(nsize);
2473 qsize += nsize;
2474 }
2475 q->set_free_with_pinuse(qsize, oldfirst);
2476 insert_chunk(q, qsize);
2477 check_free_chunk(q);
2478 }
2479
2480 check_malloced_chunk(chunk2mem(p), nb);
2481 return chunk2mem(p);
2482}
2483
2484// Add a segment to hold a new noncontiguous region
2485void malloc_state::add_segment(char* tbase, size_t tsize, flag_t mmapped)

Callers

nothing calls this directly

Calls 9

align_as_chunkFunction · 0.85
assertFunction · 0.85
chunk2memFunction · 0.85
chunk_plus_offsetMethod · 0.80
pinuseMethod · 0.80
is_inuseMethod · 0.80
chunksizeMethod · 0.80
set_free_with_pinuseMethod · 0.80

Tested by

no test coverage detected