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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:33:21+00:00 2026-06-13T18:33:21+00:00

I have a class, let’s call it Builder. It has a private member declared

  • 0

I have a class, let’s call it Builder. It has a private member declared as

vector< vector< Node >> buffers; // Node is a pure data class.

In this Builder class constructor, I do:

buffers = vector< vector< Node >>(amount);

where “amount” is only known at runtime.

During the lifetime of the builder class, several operations get called on the buffers member. The only operations I’m using are:

buffers[i].push_back(Node());
buffers[i].clear();

I’m just adding the meat of the algorithm here for reference:

// REFINE BUFFERS
// check all levels (bottom up) and group 8 nodes on a higher level
for(int d = maxdepth; d >= 0; d--){
    if(buffers[d].size() == 8){ // if we have 8 nodes
        if(isBufferEmpty(buffers[d])){ 
            buffers[d-1].push_back(Node()); // push back NULL to represent 8 empty nodes
        } else { 
            buffers[d-1].push_back(groupNodes(octree, buffers[d])); // push back parent node
        }
        buffers[d].clear(); // clear the 8 nodes on this level
    } else {
        break; // break the for loop: no upper levels will need changing
    }
}

When the Builder class object goes out of scope, it gets destroyed, and with it, its class members as well. When I’m in VS2010 debug mode, there is no problem. When in release mode, I get the following error: “Windows has triggered a breakpoint”.

The problem lies within this part of the STL:vector specification, at the _Destroy call.

void _Tidy()
    {   // free all storage
    if (this->_Myfirst != 0)
        {   // something to free, destroy and deallocate it
        this->_Orphan_all();
        _Destroy(this->_Myfirst, this->_Mylast);
        this->_Alval.deallocate(this->_Myfirst,
            this->_Myend - this->_Myfirst);
        }
    this->_Myfirst = 0;
    this->_Mylast = 0;
    this->_Myend = 0;
    }

Looking at the debugger, I can see that _Mylast has an incorrect value (0x000000000000), which is probably what causes this de-allocation to fail. I have the same result when I try to do buffers.clear() at the end. (buffers[i].clear() works fine). Also, when I just hit “continue”, my program works fine as well.

I have some output from my algorithm after it has run. What you see is the amount of elements in the individual vectors, and the adresses pointed to by buffers[i].begin() and buffers[i].end(). With “main buffer” I mean the values I get when I call buffers.begin() and buffers.end().

  Main Buffer begin: 0000000002068050
  Main Buffer end  : 0000000002068130
  buffers[0] : 0 elements, 0000000002068160 - 0000000002068160
  buffers[1] : 0 elements, 0000000002070080 - 0000000002070080
  buffers[2] : 0 elements, 0000000002068E70 - 0000000002068E70
  buffers[3] : 0 elements, 0000000001F71810 - 0000000001F71810
  buffers[4] : 0 elements, 0000000002068BB0 - 0000000002068BB0
  buffers[5] : 0 elements, 00000000020688F0 - 00000000020688F0
  buffers[6] : 0 elements, 0000000002068370 - 0000000002068370

Now my question is, how could I have corrupted _Mylast? (I’ve corrupted the heap, somehow, anyway)

This problem only started popping up when I moved an algorithm which was previously just a function defined at global scope into a class. I suspect it has to do with how C++ handles vectors as class members.

My builder class should be able to set up an amount of buffers (the vector stuff) and pop and push Nodes into these buffers for as long as it’s alive. That’s what I’m trying to achieve.

  • 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-13T18:33:22+00:00Added an answer on June 13, 2026 at 6:33 pm

    You write to buffers[d-1] even when d is zero. Could that be your issue? Out-of-bounds errors sometimes aren’t detected until later on (such as when the vector gets deallocated).

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

Sidebar

Related Questions

Greetings, I have a class (let's call it Car) that has a property of
Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()
In Visual Studio 2008 (C++) I have a class destructor (Let's call this class
I have created a separate class (let's call it class2.cs for example) and want
I have a non-Activity class (let's call it NonActivity) that needs to post a
Okay so let's say I have class A... CLASS A has a method that
I currently have a need for a custom ListViewItem class - let's call it
i have a class let's call it cell, .cms-block .cell{ width:520px; float:left;} .cms-block.wide .cell{width:
I have a class (let's call it myClass ) that implements both __hash__ and
Suppose I have a class Base which has a member variable A* my_hash. I

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.