Jump to content
  • Advertisement
Sign in to follow this  
OleKaiwalker

Different memory schemes.

This topic is 5121 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!