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 8871129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:54:19+00:00 2026-06-14T17:54:19+00:00

For a project, I have an opening table that I decided to put in

  • 0

For a project, I have an opening table that I decided to put in a std::unordered_map. Unfortunately, I am restricted to hard-coding the entire map. So, I decided to split the initialization into multiple files.

class OpeningBook
{
public:
    OpeningBook();
private:
    std::unordered_map<std::string, int> opening_database_;
    void init1();
    void init2();
    void init3();
    void init4();
    void init5();
};

and the constructor just calls the init functions:

OpeningBook::OpeningBook()
{
    init1();
    init2();
    init3();
    init4();
    init5();
}

All of which just look like this:

void OpeningBook::init1()
{
    opening_database_.insert(std::pair<std::string, int>("0001000000-10000001000000-1000001100000-1-1000",5000));
    opening_database_.insert(std::pair<std::string, int>("0001000000-10000001000000-1000000100000-1-1100",5000));
    opening_database_.insert(std::pair<std::string, int>("0001000000-10000001000000-1000000100001-1-1000",5000));
    opening_database_.insert(std::pair<std::string, int>("0001000000-10000001000000-1000000100000-1-1010",5000));
    opening_database_.insert(std::pair<std::string, int>("0001000000-10000001000000-1000000100010-1-1000",5000));
    opening_database_.insert(std::pair<std::string, int>("0001000000-10000001000000-1000000100000-1-1001",5000));
    opening_database_.insert(std::pair<std::string, int>("0001000000-10000001000000-100000010000-11-1000",0));
    opening_database_.insert(std::pair<std::string, int>("0001000000-10000001000000-100000010000-10-1100",5000));
    // continues
}

However, as soon as my code hits the opening brace in init1(), it throws a stack overflow exception. I thought that a stack overflow couldn’t occur because an unordered_map is on the heap. What’s going on? and what can I do to fix this?

  • 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-06-14T17:54:20+00:00Added an answer on June 14, 2026 at 5:54 pm

    How many items are you inserting in each initx() method? If it’s many thousands, then it’s possible that the compiler is generating code that uses a large number of temporaries on the stack, and simply asks for more stack space than there is available.

    Try splitting your initialisation methods up further and see if that solves the problem.

    A better approach might be to have a table which contains the initialisation data:

    static const struct {
        const char *str;
        int n;
    } DatabaseInitData[] = {
        {"0001000000-10000001000000-1000001100000-1-1000",5000},
        {"0001000000-10000001000000-1000000100000-1-1100",5000},
        {"0001000000-10000001000000-1000000100001-1-1000",5000},
        // etc
    };
    

    Then, in your constructor:

    OpeningBook::OpeningBook()
    {
        for (int i = 0; i < sizeof(DatabaseInitData)/sizeof(DatabaseInitData[0]); i++) {
            opening_database_.insert(std::pair<std::string, int>(
                DatabaseInitData[i].str,
                DatabaseInitData[i].n));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MFC/C++ project that uses the ActiveX Document (Automation) approach for opening
I have a maven multi-module project (boy, I've written that opening way too many
I have a project created in visual studios 2010 pro, now opening it ultimate
I have a C++ project that have like 15+ external libraries installed with a
I have a PHP project where I am opening up a premade PDF, and
Today I have upgraded a VS 2008 project to VS 2010 simply by opening
I have several different processes within a single project that I work on. I
I have a project that interacts with a database through ADO.net Data Services. The
I'm having some trouble opening an existing blackberry eclipse project I have to work
I have a project here and it has set by default that the actions

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.