BitVecShrinkToFit
Description
Reduce bitvector capacity to match its current length. Frees any unused memory allocated beyond the current length.
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in,out | Bitvector to shrink. |
Usage example (from documentation)
BitVecShrinkToFit(&flags); // Free unused capacity
Success
Returns to the caller. Capacity now equals length; any over-allocated tail bytes have been returned to the allocator. The values of stored bits are preserved.
Failure
Function cannot fail in an observable way - if the shrink-reallocation fails, the bitvector is left unchanged but the caller is not informed (the helper silently keeps the larger buffer because the data is still consistent).
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:182:
}
void BitVecShrinkToFit(BitVec *bv) {
ValidateBitVec(bv);
if (bv->length == 0) {- In
Memory.c:39:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecShrinkToFit\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Memory.c:56:
// Shrink to fit
BitVecShrinkToFit(&bv);
// Check that capacity is now closer to length
- In
Memory.c:283:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecShrinkToFit edge cases\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Memory.c:289:
// Test shrink on empty bitvec
BitVecShrinkToFit(&bv);
result = result && (BitVecLen(&bv) == 0) && (BitVecCapacity(&bv) >= 0);- In
Memory.c:294:
// Test shrink on single element
BitVecPush(&bv, true);
BitVecShrinkToFit(&bv);
result = result && (BitVecLen(&bv) == 1) && (BitVecCapacity(&bv) >= 1);
result = result && (BitVecGet(&bv, 0) == true);- In
Memory.c:299:
// Test multiple shrinks (should be safe)
BitVecShrinkToFit(&bv);
BitVecShrinkToFit(&bv);
result = result && (BitVecLen(&bv) == 1);- In
Memory.c:300:
// Test multiple shrinks (should be safe)
BitVecShrinkToFit(&bv);
BitVecShrinkToFit(&bv);
result = result && (BitVecLen(&bv) == 1);- In
Memory.c:306:
BitVecReserve(&bv, 1000);
BitVecClear(&bv);
BitVecShrinkToFit(&bv);
result = result && (BitVecLen(&bv) == 0);- In
Memory.c:459:
BitVecReserve(&bv1, cycle * 20);
BitVecShrinkToFit(&bv2);
// Verify data integrity
- In
Memory.c:482:
// Test NULL bitvec pointer - should abort
BitVecShrinkToFit(NULL);
return false;- In
Memory.c:601:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecShrinkToFit preserves bits on a large vector\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Memory.c:612:
}
BitVecShrinkToFit(&bv);
bool result = (BitVecLen(&bv) == 400);- In
Memory.c:633:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecShrinkToFit keeps the vector structurally valid\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));- In
Memory.c:641:
}
BitVecShrinkToFit(&bv);
// ShrinkToFit marks the vector dirty, so the next access runs the
Last updated on