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. */
| 3548 | with ialloc or the array is sorted. |
| 3549 | */ |
| 3550 | size_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 | |
| 3599 | void malloc_state::init(char* tbase, size_t tsize) |
| 3600 | { |
no test coverage detected