Different memory schemes.

Started by
12 comments, last by JohnBolton 19 years, 4 months ago
Hey, When designing a memory manager a good idea would be to use different allocation schemes. Fx small reqests are treated through a pool alloctor. But when a block is freed how will the wrapper know which allocator to send the block to? When working with small allocations it is important to keep the size of the header small (not bigger than 8 bytes) and with the larger allocations the header can be bigger. fx struct PoolHeader { dword bytes; PoolHeader* next; } and struct LargerHeader { Page* page dword prevBytes; dword bytes; LargerHeader* next; } With headers like that the allocator will not be able to get the size.
Advertisement
anyone?
The easiest way would just be to do PoolAlloc and PoolFree and OtherAlloc and OtherFree (making template versions if you want more new-like syntax)

If you want it to be automatic, well, you've got the size, and if the allocator is only determined by the size, then you've got everything you need to know where it came from.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Pool = array of equally sized blocks, right? If so, then you can infer the pool from the block address. And if the block does not belong to any of the pools, then it's a large block, and then you can use the header to find the size and whatnot.
Michael K.
Yes, I could search every pool, to see where the block belongs. But wouldn't that be a bit time consuming? And if the allocator have to do a search pool it would have to search every page belonging to the pool. If one page is used, a new page is allocated and they are not necessarily contiguous. Therefore you have to search different intervals of adresses within each pool. Not quite the most time-saving method.
Use some special data structure to quicken the search. Just make sure it takes less memory than adding the equivalent information to the header -- otherwise it's simpler to just do the latter. If you design the system well, the search can be very quick. E.g. if all your pools were in a contiguous block, and if they were all the same size, then finding the pool address is little more than a simple division by the pool size.
Michael K.
clicky
Yes,

what about using a identifier somehow? Perhaps use an integer to hold the allocationtype? Was that a way to do it and if yes, how would be a good way?
Anyone?
still no answer??

This topic is closed to new replies.

Advertisement