My C ++ class creates a tree structure over time. Each node in the tree is currently allocated during construction (using a new one). The node class uses only a few bytes of memory. As the tree grows, there may be 100,000 nodes; the maximum number of nodes is unknown when constructing the tree, except for the theoretical maximum of 2 ^ 33. I refer to the nodes in the tree structure with my pointer. All nodes are exempt from the destruction of the tree, and only then.
I am after a standard library container or memory allocator / pool that I can use to allocate and store nodes in my tree class, to reduce memory fragmentation and memory retrieval. I would like not to write a custom allocator. A container must have the following two properties:
- Selected objects do not move in memory, so pointers can be safely referenced.
- The class allocates memory for large blocks of objects, thereby reducing memory fragmentation. Note that I do not require the entire container to be contiguous in memory.
I don't need iterators or container search functions, as my tree structure stores pointers. What class of standard library will provide me this function and give me the least memory overhead?
source
share