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

  • Home
  • SEARCH
  • 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 4382640
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:48:15+00:00 2026-05-21T12:48:15+00:00

this is probably something stupid, but i can’t figure it out. I’m getting a

  • 0

this is probably something stupid, but i can’t figure it out. I’m getting a std::bad_alloc exception in the following code snippet (which is a case statement in a switch):

case 0:
{
MyPrimitiveNode* node = new MyPrimitiveNode( 1, false );
TheStack.push_back( MyStackItem( node, TYPE_REF ) ); // bad_alloc here
break;
}

Where TheStack is of type MyStack, which is a typedef std::vector<MyStackItem> MyStack;

MyStackItem is a simple structure and looks like this:

struct MyStackItem {
    MyNode* value;
    uint8_t type;

    MyStackItem() {
        value = NULL;
        type = TYPE_UNDEF;
    }

    MyStackItem( MyNode* val, uint8_t t ) {
        value = val;
        type = t;
    }
};

As for MyNode nad MyPrimitiveNode, they come from another project (a static lib) and are defined as follows:

class MyNode
        {
        public:
            MyNode() {}
            virtual ~MyNode() {}
        };

class MyPrimitiveNode : public MyNode
    {
    public:
        bool bDeclaration;
        uint32_t u32ObjectIdx;

        MyPrimitiveNode() {
                        bDeclaration = false;
                        u32ObjectIdx = 0;
                    }
        MyPrimitiveNode( uint32_t id, bool declaration ) {
                        bDeclaration = declaration ;
                        u32ObjectIdx = id;
                    }
        ~MyPrimitiveNode() {}
    };

Hope this is all relevant info that is needed. I know that MyStackItem does only a shallow copy, this is how i want it. Dont worry about leaks, thats handled elsewhere.

Can someone tell my what is going on and how can i fix it? Thanks.

EDIT: posting the stack trace might help:

>   myProgram.exe!std::_Construct<MyStackItem,MyStackItem>(MyStackItem* _Ptr=0x003d3de8, const MyStackItem& _Val={...})  Line 52 + 0x33 bytes   C++
    myProgram.exe!std::allocator<MyStackItem>::construct(MyStackItem* _Ptr=0x003d3de8, const MyStackItem& _Val={...})  Line 155 + 0xd bytes C++
    myProgram.exe!std::_Uninit_fill_n<MyStackItem*,unsigned int,MyStackItem,std::allocator<MyStackItem> >(MyStackItem* _First=0x003d3de8, unsigned int _Count=0x00000001, const MyStackItem& _Val={...}, std::allocator<MyStackItem> & _Al={...}, std::_Nonscalar_ptr_iterator_tag __formal={...}, std::_Nonscalar_ptr_iterator_tag __formal={...})  Line 400 + 0x10 bytes  C++
    myProgram.exe!stdext::unchecked_uninitialized_fill_n<MyStackItem*,unsigned int,MyStackItem,std::allocator<MyStackItem> >(MyStackItem* _First=0x003d3de8, unsigned int _Count=0x00000001, const MyStackItem& _Val={...}, std::allocator<MyStackItem> & _Al={...})  Line 922 + 0x43 bytes C++
    myProgram.exe!std::vector<MyStackItem,std::allocator<MyStackItem> >::_Ufill(MyStackItem* _Ptr=0x003d3de8, unsigned int _Count=0x00000001, const MyStackItem& _Val={...})  Line 1252 + 0x18 bytes    C++
    myProgram.exe!std::vector<MyStackItem,std::allocator<MyStackItem> >::_Insert_n(std::_Vector_const_iterator<MyStackItem,std::allocator<MyStackItem> > _Where={value={...} type=??? }, unsigned int _Count=0x00000001, const MyStackItem& _Val={...})  Line 1184 + 0x14 bytes C++
    myProgram.exe!std::vector<MyStackItem,std::allocator<MyStackItem> >::insert(std::_Vector_const_iterator<MyStackItem,std::allocator<MyStackItem> > _Where={value={...} type=??? }, const MyStackItem& _Val={...})  Line 878  C++
    myProgram.exe!std::vector<MyStackItem,std::allocator<MyStackItem> >::push_back(const MyStackItem& _Val={...})  Line 823 + 0x58 bytes    C++
    myProgram.exe!MethodWhereExceptionOccurs
  • 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-21T12:48:16+00:00Added an answer on May 21, 2026 at 12:48 pm

    That stack trace doesn’t show anything that would lead me to believe that some part of the push_back is requesting a ton of memory.

    Therefore, that pretty much leaves the option that your program has corrupted the heap somewhere ELSE and this allocation is the victim. Without more code and details all I can suggest is a memory checker like valgrind.

    Does MyStackItem have a destruction you aren’t showing us?

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

Sidebar

Related Questions

I'm probably doing something stupid but I can't figure out what it is. The
This is probably really stupid but i can't find the problem with my code.
I get the feeling this is probably something I should know but I can't
I'm probably doing something realy stupid but I cant get this to work: var
This is probably something very simple but I'm not getting the results I'm expecting.
I'm probably doing something stupid, but I can't spot it. I've installed Eclipse Helios
This is probably something fundamental and stupid that I've missed, but the various workarounds
This is probably stupid simple, but for some reason I'm having trouble getting it
This probably sounds really stupid but I have noo idea how to implement jquery's
This is probably something simple but it's driving me nuts. I'm making some pagination

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.