Memory Manager | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Memory Manager

Hey. I made this simple memory manager and was wondering if anyone has experience in this field. Specifically I want to learn how to avoid fragmentation and such.. https://code.sololearn.com/c82PJR0bb7tc/?ref=app If I make each entry a fixed size (larger than anything stored), will this fix any fragmentation issues?

11th Aug 2017, 3:44 AM
jay
jay - avatar
7 Answers
+ 7
fair enough 😊 it is for learning game programming mostly. i have read that pretty much all "large" games utilize custom memory managers. it probably overkill but at least I will know how it is done for future reference
11th Aug 2017, 11:14 PM
jay
jay - avatar
+ 5
Speed and to ensure there is enough memory on execution at runtime for the program to run. I hear tell memory allocations can be a bottleneck. so to alleviate this we can grab a big chunk of memory at execution and fill that as required. If this chunk gets fragmented over time we may/will end up with spaces that can not be filled with anything and therefore is essentially lost.
11th Aug 2017, 1:35 PM
jay
jay - avatar
+ 5
i found this i am going to try. thought i'd leave it here for anyone who might be interested https://www.codeproject.com/articles/1083210/an-efficient-cplusplus-fixed-block-memory-allocato
11th Aug 2017, 1:49 PM
jay
jay - avatar
+ 4
but fragmentation will still occur will it not?
11th Aug 2017, 1:25 PM
jay
jay - avatar
+ 3
I understood the point, but I think it is too much work for it. If my program has to allocate and relocate memory frequently to some class object, I would just create an object in the outer scope and use a function to reinitialize it instead of creating a new one.
11th Aug 2017, 11:05 PM
Denis Felipe
Denis Felipe - avatar
+ 2
Check something named RAII and smart pointers. If you learn to use those, you won't worry with memory leaks anymore.
11th Aug 2017, 1:23 PM
Denis Felipe
Denis Felipe - avatar
+ 2
Sorry, I fail to see any benefit in avoiding memory to get fragmented. Can you explain what you need that for, please?
11th Aug 2017, 1:28 PM
Denis Felipe
Denis Felipe - avatar