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

Method internal_bulk_free

libCacheSim/dataStructure/sparsepp/spp_dlalloc.h:3550–3597  ·  view source on GitHub ↗

Try to free all pointers in the given array. Note: this could be made faster, by delaying consolidation, at the price of disabling some user integrity checks, We still optimize some consolidations by combining adjacent chunks before freeing, which will occur often if allocated with ialloc or the array is sorted. */

Source from the content-addressed store, hash-verified

3548 with ialloc or the array is sorted.
3549*/
3550size_t malloc_state::internal_bulk_free(void* array[], size_t nelem)
3551{
3552 size_t unfreed = 0;
3553 if (1)
3554 {
3555 void** a;
3556 void** fence = &(array[nelem]);
3557 for (a = array; a != fence; ++a)
3558 {
3559 void* mem = *a;
3560 if (mem != 0)
3561 {
3562 mchunkptr p = mem2chunk(mem);
3563 size_t psize = p->chunksize();
3564#if SPP_FOOTERS
3565 if (get_mstate_for(p) != m)
3566 {
3567 ++unfreed;
3568 continue;
3569 }
3570#endif
3571 check_inuse_chunk(p);
3572 *a = 0;
3573 if (rtcheck(ok_address(p) && ok_inuse(p)))
3574 {
3575 void ** b = a + 1; // try to merge with next chunk
3576 mchunkptr next = (mchunkptr)p->next_chunk();
3577 if (b != fence && *b == chunk2mem(next))
3578 {
3579 size_t newsize = next->chunksize() + psize;
3580 set_inuse(p, newsize);
3581 *b = chunk2mem(p);
3582 }
3583 else
3584 dispose_chunk(p, psize);
3585 }
3586 else
3587 {
3588 SPP_ABORT;
3589 break;
3590 }
3591 }
3592 }
3593 if (should_trim(_topsize))
3594 sys_trim(0);
3595 }
3596 return unfreed;
3597}
3598
3599void malloc_state::init(char* tbase, size_t tsize)
3600{

Callers 1

mspace_bulk_freeFunction · 0.80

Calls 5

mem2chunkFunction · 0.85
get_mstate_forFunction · 0.85
chunk2memFunction · 0.85
chunksizeMethod · 0.80
next_chunkMethod · 0.80

Tested by

no test coverage detected