# Does This Memory Managment Method Have a Name?

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

## Recommended Posts

I had just writen a memory management system for a simple particle engine that will be part of a game, but I don't know exactly what I want to call the classes involved. It's basically a double linked list with pointers for active and inactive nodes. All the nodes used are allocated before gameplay begins, so there would not be any dynamic allocating and deallocating during play. Simplified Ex.
class Node
{
public:
void do_something();

// Note, previous is not used much in this example, but is needed
// when removing nodes which are not at the beginning of the list
Node *previous;
Node *next;
};

class MemoryManager
{
public:
void init(unsigned int number_of_nodes);
void activate();    // Makes the first inactive node active
void deactivate();  // Makes the first active node deactivate
void deactivate(Node *node);  // Deactivate a specified node
void do_active();   // Calls do_something() in all active nodes

unsigned int node_count;
Node *nodes;     // All of the nodes allocated
Node *active;    // Points to starting node of active nodes
Node *inactive;  // Points to starting node
};

So, the initial state may be: Note: i is node, p is previous, n is next, nothing is NULL Nodes is sequential, while active and inactive follow the next pointers Nodes: {i=0, n=1} {i=1, p=0, n=2} {i=2, p=1, n=3} {i=3, p=2} Active: Inactive: {i=0, n=1} {i=1, p=0, n=2} {i=2, p=1, n=3} {i=3, p=2} After activating one node: Nodes: {i=0} {i=1, n=2} {i=2, p=1, n=3} {i=3, p=2} Active: {i=0} Inactive: {i=1, n=2} {i=2, p=1, n=3} {i=3, p=2} After activating another: Nodes: {i=0, p=1} {i=1, n=0} {i=2, n=3} {i=3, p=2} Active: {i=1, n=0} {i=0, p=1} Inactive: {i=2, n=3} {i=3, p=2} After deactivating one: Nodes: {i=0} {i=1, n=2} {i=2, p=1, n=3} {i=3, p=2} Active: {i=0} Inactive: {i=1, n=2} {i=2, p=1, n=3} {i=3, p=2} Let's say we now have this after adding a few nodes: Nodes: {i=0, p=1} {i=1, p=2, n=0} {i=2, n=1} {i=3} Active: {i=2, n=1} {i=1, p=2, n=0} {i=0, p=1} Inactive: {i=3} And now we deactivate node 1 (which can become a little messy looking): Nodes: {i=0, p=2} {i=1, n=3} {i=2, n=0} {i=3, p=1} Active: {i=2, n=0} {i=0, p=2} Inactive: {i=1, n=3} {i=3, p=1} You get the idea. What might this be called, or does it even have a name? I don't want to just call the class 'MemoryManager' that would be confusing in the long run. Also, I hope some may find this information useful, though I didn't get into implimentation much.

##### Share on other sites
Without the active list (and without the previous-pointer required for it) it would be a memory pool with free list scheme.

##### Share on other sites
It's memory pooling.

It's also a horrible implementation that reinvents many wheels, all poorly, and lacks all kinds of flexibility.

Note that the concept of "do something to all active nodes" is completely separate from the idea of memory management. If you wanted to keep this thing, it should be cast as a manager of that particular node type, and might in turn be implemented in terms of a more general "memory manager".

##### Share on other sites
Ok. Maybe 'memory management' was not exactly the best choice of terms. Also, that was example code (not the actual code) to give a general idea as to what is going on. I wanted to make it general in the sense that it can be used for more than just active and inactive particles moving around the screen. If there is a better way, what wheel am I reinventing?

##### Share on other sites
std::list and boost::pool

##### Share on other sites
I suppose you're right. I used std::list for some other things, but I didn't know if there would be some overhead for adding and removing particles (I suppose it is sufficiently optimised, so what was I thinking?). Also, I thought working out this problem was kind of fun. Oh well.

##### Share on other sites
It's basically a free list. I would say it is a free list, but wikipedia includes details in the definition that make your implementation only similar. You're also using a Memory Pool.

1. 1
2. 2
Rutin
22
3. 3
JoeJ
18
4. 4
5. 5

• 15
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631725
• Total Posts
3001905
×