Original Post
🔒 Locked
SmallObjectAllocator
Advertisement
Yes, you would want to use multiple allocators for different kinds of objects of similar size in order to keep memory fragmentation (and thus, cpu cache fails) at a minimum.
If the size of objects managed by the small object allocator differs greatly, you''ll also waste a lot of memory because each object takes as much memory as the largest object the allocator could possibly host.
It will also be faster (and more convenient) if you work with small helper classes like vectors and matrices on the stack instead of allocating them in the heap (with or without the small object allocator).
-Markus-
If the size of objects managed by the small object allocator differs greatly, you''ll also waste a lot of memory because each object takes as much memory as the largest object the allocator could possibly host.
It will also be faster (and more convenient) if you work with small helper classes like vectors and matrices on the stack instead of allocating them in the heap (with or without the small object allocator).
-Markus-
quote:
It will also be faster (and more convenient) if you work with small helper classes like vectors and matrices on the stack instead of allocating them in the heap (with or without the small object allocator).
So one would have to write a manager to take care of the various allocators? Could someone explain the stack vs. heap thing to me cos my knowledge is a tad hazzy!
[edited by - TonyFish on April 29, 2004 9:10:22 AM]
I don't think you should be worrying about using a custom allocator if you don't know the difference between the stack and the heap... Try this for starters.
It's been said many times before but it bears repeating because noone ever seems to take it in... Premature Optimization is the Root of All Evil Just write your program with clean code and sensible algorithms and get it working. If it's fast enough, you're done. If it's not profile and optimize the bottlenecks. Memory allocation really shouldn't be an issue in a PC game unless you're doing something stupid. If you're doing something stupid (like allocating and freeing 1000s of objects every frame), fix it by not allocating 1000s of objects every frame rather than trying to use some super-clever custom allocator that you don't really understand. Only if you have some very specific case where you've really thought about it and can't see a better solution should you use a custom allocator - a particle system perhaps. Using a custom allocator for everything is very unlikely to be necessary and just adds unnecessary complexity.
I have great respect for Andrei Alexandrescu btw - I'm not suggesting his code isn't useful, just that you shouldn't use it unless you have a very clear need for it. Don't add unneccessary complexity until you absolutely have to.
[edited by - mattnewport on April 30, 2004 2:34:56 AM]
It's been said many times before but it bears repeating because noone ever seems to take it in... Premature Optimization is the Root of All Evil Just write your program with clean code and sensible algorithms and get it working. If it's fast enough, you're done. If it's not profile and optimize the bottlenecks. Memory allocation really shouldn't be an issue in a PC game unless you're doing something stupid. If you're doing something stupid (like allocating and freeing 1000s of objects every frame), fix it by not allocating 1000s of objects every frame rather than trying to use some super-clever custom allocator that you don't really understand. Only if you have some very specific case where you've really thought about it and can't see a better solution should you use a custom allocator - a particle system perhaps. Using a custom allocator for everything is very unlikely to be necessary and just adds unnecessary complexity.
I have great respect for Andrei Alexandrescu btw - I'm not suggesting his code isn't useful, just that you shouldn't use it unless you have a very clear need for it. Don't add unneccessary complexity until you absolutely have to.
[edited by - mattnewport on April 30, 2004 2:34:56 AM]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement