Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct DoingTheNastyAllocator(Allocator, size_t chunkSize) {
- enum size_t alignment = 16;
- Allocator allocator;
- void[] heap;
- void[] allocate(size_t size) {
- immutable actSize = (size + 15) & ~15;
- if (actSize <= heap.length) {
- void[] buf = heap[0..size];
- heap = heap[actSize..$];
- return buf;
- }
- if (actSize > chunkSize)
- return allocator.alloc(size);
- void[] buf = allocator.alloc(chunkSize);
- heap = buf[actSize..$];
- return buf[0..size];
- }
- void deallocate(void[] buf) { /* lol */ }
- void deallocateAll() { allocator.deallocateAll() } // lol here too?
- static typeof(this) it = typeof(this)();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement