sebbbi / offsetallocator Goto Github PK
View Code? Open in Web Editor NEWFast O(1) offset allocator with minimal fragmentation
License: MIT License
Fast O(1) offset allocator with minimal fragmentation
License: MIT License
Should the maxAllocs
constructor parameter correspond to the maximum number of times allocate
can be called? 'Cause if so, it's a bit off I think.
Here's a test case:
OffsetAllocator::Allocator allocator(36864, 2);
OffsetAllocator::Allocation a = allocator.allocate(32);
REQUIRE(a.offset == 0);
OffsetAllocator::Allocation b = allocator.allocate(32);
REQUIRE(a.offset == 0);
OffsetAllocator::Allocation c = allocator.allocate(32);
REQUIRE(a.offset == OffsetAllocator::Allocation::NO_SPACE);
allocator.free(a);
allocator.free(b);
allocator.free(c);
It fails on the first REQUIRE.
Thanks for open-sourcing this code by the way. I'm testing it out in my C# homebrew engine, it seems to work well so far :-)
Hi,
Maybe I'm too tired still and had a brain fart, but I think this line:
return (mantissa | MANTISSA_VALUE) << (exponent - 1);
should be changed to:
return (mantissa & MANTISSA_MASK) << (exponent - 1);
here
https://github.com/sebbbi/OffsetAllocator/blob/3610a7377088b1e8c8f1525f458c96038a4e6fc0/offsetAllocator.cpp#L121C28-L121C28
Otherwise it'll always return the full mantissa mask regardless of the input.
Great job on the allocator, it performs very well in my project!
Best,
Pontus
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.