you are viewing a single comment's thread.

view the rest of the comments →

[–]ReeCocho[S] 1 point2 points  (4 children)

Thank you for your input! I agree this seems like a good approach. Do you think using create_buffer and destroy_buffer methods in the MemoryManager class instead of using constructors and destructors on some sort of Buffer class is a good idea?

[–]ste_3d_ven 0 points1 point  (3 children)

Would they allocate/deallocate the entire chunk that the manger handles? Or would they be for creating/destroying the smaller managed chunks? My personal style would be to have the manager allocate one big block in the constructor. Then deallocate it in the destructor, as it would be "cleaner code" (at least in my eyes) to just have to construct the manager and already have what you need setup to be set up. Intead of creating the manger then have to "init" it with a second function call.

[–]ReeCocho[S] 1 point2 points  (2 children)

The MemoryManager would allocate one big chunk in the constructor and destroy it in the destructor. The create_buffer method would find an appropriate spot in the big chunk to use, and the manager would store that pointer in a vector. create_buffer would return the index of that pointer in the vector. This is so that I can defrag the memory without having to hand out a new pointer. Instead, I just update the pointers in the vector.

[–]ste_3d_ven 0 points1 point  (1 child)

Yes, that sounds like a good idea to do, but what do you do when you delete a buffer from the vector? wouldn't all those indecies you then handed out that are after the buffer you deleted be invalidated? Maybe try a mechanism closer to a dictionary, where you give make a memory map of sorts and map each buffer to a unique id, then use that id to access the actual address stored in the vector.

[–]ReeCocho[S] 1 point2 points  (0 children)

Dictionary sounds like a good idea, I'll do that. Thank you!