BitMagic icon indicating copy to clipboard operation
BitMagic copied to clipboard

Allocation Control Question

Open tamboril opened this issue 6 months ago • 5 comments

In my application, I can't afford to have bm allocate after all initialization is done. How can I initialize the allocator or bvector such that it is guaranteed not to allocate further given a max size of N bits?

tamboril avatar Jul 06 '25 23:07 tamboril

BM allocates in blocks of 64K bits (or less) on demand, so if you are not setting beyond N - it will not allocate. bvector will also do not allocate in between 0 and N if you are not setting bits in the block ranges. No special allocator is necessary.

tlk00 avatar Jul 07 '25 13:07 tlk00

So it seems that to "warm up" the allocator deterministically, I would have to pre-set a bit in each block range. Can you show a short example of doing that for an arbitrary N? For scale, my N may be in the millions.

tamboril avatar Jul 08 '25 13:07 tamboril

Not really a full example but something like:

for (unsigned i = 0; i < N; i+=65536)
{
     bv.set(i); // allocates a block, bit can be cleared immediately
}

tlk00 avatar Jul 10 '25 21:07 tlk00

Ok. Thank you. That would make a useful "reserve(nBits)" method. That's what I do on vectors and unordered_maps at init time.

On Thu, Jul 10, 2025 at 4:44 PM Anatoliy Kuznetsov @.***> wrote:

tlk00 left a comment (tlk00/BitMagic#82) https://github.com/tlk00/BitMagic/issues/82#issuecomment-3059200768

Not really a full example but something like:

for (unsigned i = 0; i < N; i+=65536) { bv.set(i); // allocates a block, bit can be cleared immediately }

— Reply to this email directly, view it on GitHub https://github.com/tlk00/BitMagic/issues/82#issuecomment-3059200768, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4B47LGUGQ3W2G5GNN5MIL3H3NEHAVCNFSM6AAAAACA4YQOLKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTANJZGIYDANZWHA . You are receiving this because you authored the thread.Message ID: @.***>

tamboril avatar Jul 11 '25 00:07 tamboril

Sure, good suggestion. Will add it soon.

tlk00 avatar Jul 11 '25 14:07 tlk00