Memory Management
I've never coded a memory management system of my own. Is such a thing really necessary for most applications that run for an extended amount of time, or is this only advisable for games ad other apps that do a lot of new/deletes? And does the builtin OS-memory management suck so bad it can't be trusted with this task at all?
No,
I did this mostly for the purpose of selfeducation and to see if my allocator would be more efficient. I also like the ability to easily retrieve memory allocation statistics and to catch memory leaks and other memory related errors.
I did this mostly for the purpose of selfeducation and to see if my allocator would be more efficient. I also like the ability to easily retrieve memory allocation statistics and to catch memory leaks and other memory related errors.
Memory intensive programs will eventually run out of memory or suffer performance issues using the normal new and delete functions. Writing custom managers will allow the application to system memory more efficiently so that the program can run faster longer.
90% of the time, on a computer with paged virtual memory (such as your PC), the standard memory manager is all you need.
Before you decide to implement your own memory manager, you should make sure that memory management is really a bottleneck, and that your memory manager will perform better than the standard, and that it doesn't create more problems than it solves.
Before you decide to implement your own memory manager, you should make sure that memory management is really a bottleneck, and that your memory manager will perform better than the standard, and that it doesn't create more problems than it solves.
I trying to make my mm with design #1, but I ran into some complications. To insure that my mm isn't fixed-size, I want to make it possible for the mm to create an extra heap, when no fitting free blocks are found. But when 2 or more heaps are inserted, it becomes complicated to find the one, in which deallocated should inserted.
One solution is to do a linear search through every heap, and eventually the right memory location will come up.
That is of course a very stupid and time consuming way of doing it.
Another solution could be to see which heap, that contains the address, and therefor can all the other time consuming calculations be left out, simply be seach every heap, intill a heap matches this statment.
if (heap->addr <= block && block > (heap->addr + heap->nBlocks))
Now my question is... Is there a better way? Some other way to manages the heaps?
And last, can the previous statment be optimized some way?
One solution is to do a linear search through every heap, and eventually the right memory location will come up.
That is of course a very stupid and time consuming way of doing it.
Another solution could be to see which heap, that contains the address, and therefor can all the other time consuming calculations be left out, simply be seach every heap, intill a heap matches this statment.
if (heap->addr <= block && block > (heap->addr + heap->nBlocks))
Now my question is... Is there a better way? Some other way to manages the heaps?
And last, can the previous statment be optimized some way?
look here under "Wilderness Preservation":
http://g.oswego.edu/dl/html/malloc.html
I don't do that my pool size is fixed :)
http://g.oswego.edu/dl/html/malloc.html
I don't do that my pool size is fixed :)
Right, I've just been reading Stroustrup on allocators, and if I'm getting what he wrote correctly, then allocators basically are ... hmm ... memory management systems kind of, is that correct? So if one wants to write his own memory management, would it make sense to make your own allocator? Has anyone actually done this?
Also, can someone point me to a VERY simple tutorial on allocators. I'd like to think I'm a fairly decent C++ programmer, but reading Stroustrup has got my head steaming.
Also, can someone point me to a VERY simple tutorial on allocators. I'd like to think I'm a fairly decent C++ programmer, but reading Stroustrup has got my head steaming.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement