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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:16:52+00:00 2026-05-21T03:16:52+00:00

thank you for looking at my problem. I have an object that is being

  • 0

thank you for looking at my problem.

I have an object that is being dynamically created in my program. The creation is part of a loop and the first iteration works fine.

Upon creation, my object base class adds itself to a map.

Here is some sample code :

public class Base {  
    Base() {
        // Add itself to a map
        Data::objects[key] = this;
    }
}

public class Derived : public Base {
    // This ctor only initialize one int field.
    Derived() : Base() {};
}

Kinda simple isn’t it ?

In my code, I do Derived * d = new Derived(); and for some silly reason, I get a SIGSEGV.

I tried to debug it, but it doesn’t even enters the ctor before crashing!

Here is my call stack so you can help me better:

Address: @0x002c0000
ntdll!RtlReleasePebLock()
Address: @0x0000000c at c:…\stl_deque.h:514
msvrct!malloc()
libstdc++-6!_Znwj()
fu87_ZSt4cerr(this=0xbc1ad8, e=”//my object name//”) at //my object name//.cpp
… Other are my lines.

Thank you, Micael

{enjoy}

Edit: Adding informations about the map

The map is located in a data class, statically.

// Data.h
class Data {
    static map<int, Base*> objects;
}

// Data.cpp
#include "Data.h"
map<int, Base*> Data::objects;

// methods implementations

How can you corrupt the heap, how can I find a corruption has occured?

  • 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-21T03:16:53+00:00Added an answer on May 21, 2026 at 3:16 am

    Has Data::objects been initialized prior to the creation of ANY of the usages of Base?

    You are not guaranteed that the class object objects had been initialized whenever you have more than one translation unit (read, .cpp file) in the final link target, unless you’ve gone to special effort to ensure it.

    Most people solve this problem by using a static class through which this initialization is guaranteed to have occurred on first use. Something like:

    // untested code, typed in by hand, not compiled through a machine compiler.
    class Base {
        public: static addObject(Base* that);
        Base::Base() { Base::addObject(this); }
    };
    class Derived: public Base {
        Derived::Derived() {}
    };
    //
    // and in the .CPP for Base
    namespace /* hidden */ {
        int object_number = 0;
        map<int,Base*> *objects = NULL;
    }
    void Base::addObject(Base* that) {
        // TODO: do something to avoid multi-thread issues if that is ever a concern
        if (!objects) {
            objects = new map<int,Base*>();
        }
        (*objects)[++object_number] = that;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks for looking on this problem. I have a page that is totally valid
Problem I currently have a factory that depends on a few parameters to properly
I have a throughput problem with DELETE/INSERT sequences on PostgreSQL 9.0. I am looking
I have a multithreaded server C++ program that uses MSXML6 and continuously parses XML
thank you for looking i got this example from my book but i cant
Thank you for the answers. :) I'm mainly looking to host my website with
I am looking for a better solution than what we currently have to deal
Looking at the C# and VB.NET language specs I think it says that the
Figure there is a simple solution to this problem but I have been unable
I have kind of a unique problem in the project I'm working in. What

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.