Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6970257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:41:12+00:00 2026-05-27T16:41:12+00:00

I want to understand how to store a graph with huge data. I am

  • 0

I want to understand how to store a graph with huge data. I am designing an application which has a graph of huge railway route network. Where vertices are the railway station name. I have designed using adjacency list in C++. But now i found that it is consuming very high memory and sometime i also get no-memory error. I was wondering how such huge graph are stored so that algorithm on the graph can be used.

Graph is defined as

std::map<std::string, std::set<std::string> > railway_graph;

or how does google/facebook store there graph data structure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:41:13+00:00Added an answer on May 27, 2026 at 4:41 pm

    Your choice of data structure will require a lot superfluous memory, dynamically allocated on the heap. std::map and std::string will allocate a piece of memory for each single entry (plus its own overhead). std::string will also allocate a piece of memory for the string.

    This is comfortable and totally ok for many cases. But not ok for large data structures.

    In the end you have a map, which contains pointers (which itself were allocated one by one) to sets, which contains pointers (which itself were allocated one by one) to strings, which contain pointers to the actual string buffers.

    Your actual problem is the overhead that dynamic allocation incurs. On most platforms, a heap allocation requires an extra 16-byte of memory just for heap management (though the numbers vary…).

    I suggest, that you re-define your graph in the following way:

    // a list of node names, its index (a size_t) is used in the following data structures
    // - alternatively, you may use an std::map<int,std::string> here, to simplify the
    //   "index" to "name" lookup...
    typedef size_t NodeId;
    typedef std::vector<std::string> NodeList;
    
    // an edge
    typedef std::pair<NodeId,NodeId> Edge;
    // or alternatively:
    struct Edge {
        NodeId from, to;
    };
    
    // a plain list of edges
    typedef std::vector<Edge> EdgeList;
    

    Or, alternatively the following data structures may be easier for your use cases. It is similar to your example, but is much more compact in memory representation:

    // a list of node names, its index (a size_t) is used in the following data structures
    typedef size_t NodeId;
    typedef std::vector<std::string> NodeList;
    
    typedef std::vector<NodeId> NodeIdList;
    
    // a map from one node to its adjacent nodes
    typedef std::map< NodeId, NodeIdList > Graph;
    

    EDIT: Added and used NodeIdList …

    If this still consumes too much memory, then you should think about keeping data on disk and loading it on demand.

    If your node names are constant, then you should also think about some kind of string-table, a more compact representation of string data in memory. But this is rather low-level stuff.

    Try to use better data structures first!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my ASP.NET web application, I want to store an array of data that
Well if i want to store data for a application machine wide i just
I have a .exe app which I want to understand better - I can
I want to store a list of data records in a NSMutableArray for use
The web service that I want to run on AWS has to store and
I am creating an Entity Data Model for a document. I want to store
I store user data in a MSSQL table called Users. What I want to
I want to store some data into byte arrays in Java. Basically just numbers
I have an XML file which I want to store on the users machine.
I understand that there's no String data type in C. What I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.