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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:39:42+00:00 2026-05-28T02:39:42+00:00

EDIT: solved, I know how but I don’t understand why. I changed variables declaration

  • 0

EDIT: solved, I know how but I don’t understand why.

I changed variables declaration from

tr1::unordered_map<int,T> variables;

to

unordered_map<int,T> variables;

and it’s work fine.

If you know why please write it in the answers.

I have a very large program, so I don’t know which code I should bring here.

There is abstract class, that inherits with derived class.
The abstract have unordered_map<int,int> (template) as private member, and public method insert(int,int).

The derived class use the base class insert method to insert elements to the unordered_map<int,int> container,

The first int uses like counter and start with 0. The first eleven insert elements going O.K. but in the 12th element I get sigsegv,and fault in struct equal_to at stl_function.h(209).

In the debugger I have saw that the unordered_map’s bucket_count equal to 11, maybe it’s clue for something.

My compiler is gcc 4.6.1.

Maybe you can write in general what can cause sigsegv in unordered_map.insert?

Thank you, and sorry about my poor English.

I will bring specific code, if I know which.

EDIT:
This is the insert method:

virtual void Insert(int arrayPlace, T value)
{
    if (!isReadOnly)
    {            
        if (IsValueDataValid(value))
        {
           variables[arrayPlace] = value;
        }
        else
        {
            throw 2;
        }            
    }
    else
    {
        throw 4;
    }
};

The declaration is:

tr1::unordered_map<int,T> variables;

The sigsegv happend when arrayPlace==11, And it dosn’t matter what value equal.

  • 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-28T02:39:43+00:00Added an answer on May 28, 2026 at 2:39 am

    The answer to the question is very simple: if you use the code correctly, no segmentation fault will be created by std::unordered_map! So the question becomes: what are typical user errors when using std::unordered_map? Off-hand I would think immediately of three issues:

    1. The objects are placed into the map as values. That is, the objects need be copyable or movable. That is, I would investigate whether the type T you got correctly implements copy construction. In particular, you want to pay attention to the copy constructor if it isn’t in the class but the class has an assignment operator or a destructor.
    2. The hash key computed isn’t really a hash key but something possibly depending on the location of the object. This would cause funny behavior because the object move to some extend (although once they are inserted they stay put).
    3. Similar to the previous issue, the equality operation isn’t really an equality operation. The unordered map needs the equality operator to determine if two objects with the same hash code are indeed the same.

    Given that the key is an int and the hash code and equality are provided I would concentrate on the first issue. That is, I would concentrate on this once I have proved that the use of the std::unordered_map is indeed the problem: the segmentation violation may also quite easily result from things being messed up earlier. For example, something may have overwritten memory or deleted memory the wrong way, etc. Tools like purify or valgrind can help finding these issue. In any case, you want to boil down the program to a minimal crashing example. Typically I find that the issue becomes obvious in the process.

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

Sidebar

Related Questions

edit #2: Question solved halfways. Look below As a follow-up question, does anyone know
UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
I don't know exactly how it happened, but I have a versioned .svn directory
EDIT: This question is solved, but I can't accept my own answer just yet.
Edit: I solved my problem but if you have anything to add please do.
i get this error, and i don't know how can be solved. I read
Edit : Solved, there was a trigger with a loop on the table (read
Edit: Solved. Hi, I'm starting with Qt, I try to connect a slot to
Edit: I have solved this by myself. See my answer below I have set
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone

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.