c++ - Good memory management strategies for graph datastructures -


For me, on many occasions and for many employers, my own graph datastructure was the reason for applying full access For flexibility, I often call it two classes, a node class and a edge / class.

need to be used. A set of outgoing edges (and possibly incoming edges) and one edge will have one source and one sink (managed points for both nodes) are often cycles of these articles.

My question is: What is the best way to manage memory in such graph data structures, especially when you are converting and mutating the graph? Due to the presence of the wheel, they do not lend themselves to calculate the reference (even if you try to use weak signals, it is often not clear where the wheel is and where the weak links are located).

In my various implementation, I have kept track of all the allocated nodes and edges, different from the graph as well as a list of entry points on the graph. I have applied then that is a simple garbage collector. At regular intervals, I run the GC after implementing different graph changes (including unlinking some nodes / edges), which include:

  1. Starting from the entry point nodes and all from there Marking the nodes and edges to reach the active through the graph (via BFS / DFS).
  2. Reflected on all the nodes and edges in the entire set and not marked in the previous step.

    It works well (and it is a simple implementation of the mark / sweep) but it always ends in a small clumsy appearance. Does anyone have any insights on this issue, or better alternative solutions?

    When you do finite graphs, they can not be displayed as pointer structures instead ,

    • A list of edges ( vector , list , whatever,] and list of vertices or Use <
    • to display a matrix (2-D array) of a mapping for index ( map or unordered_map ) and boolean (or float for weighted graph) Is that the top i and j are connected.

      The former representation is called one, the latter one. Which graph is used by you, depending on the article and the operation Both are very simple in terms of memory management and tend to perform more often than pointer structures because they take less memory and preserve the area of ​​reference.

Comments