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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:18:34+00:00 2026-05-24T20:18:34+00:00

In my code I have a vector defined: vector<vector<vector<vector<shared_ptr<foo> > > > > fooBoxes;

  • 0

In my code I have a vector defined:

vector<vector<vector<vector<shared_ptr<foo> > > > > fooBoxes;

I am initializing the vector using:

int BOX_NUM = 12 //this is actually defined elsewhere

fooBoxes.resize(BOX_NUM);
for (int i = 0; i<BOX_NUM; i++){
  fooBoxes[i].resize(BOX_NUM);
  for (int j = 0; j < BOX_NUM; j++){
    fooBoxes[i][j].resize(BOX_NUM);
    for (int k = 0; k < BOX_NUM; k++){
      fooBoxes[i][j][k].resize(0);
    }
  }
}

I suspect that the use of vector is causing me a segmentation fault and I want to replace fooBoxes to be:

vector<vector<vector<set<shared_ptr<foo> > > > > fooBoxes

what do I do in the for loops? simply remove the resize(0) part?

Edit:
This is the output of valgrind in the crash:

==2258== Invalid read of size 8
==2258==    at 0x439237: trans(int) (stl_iterator.h:704)
==2258==    by 0x413B0E: membrane::MCstep(int) (membrane.cpp:490)
==2258==    by 0x402767: main (main.cpp:14)
==2258==  Address 0x7932420 is 8 bytes after a block of size 24 free'd
==2258==    at 0x4A05743: operator delete(void*) (vg_replace_malloc.c:346)
==2258==    by 0x405636: vec::~vec() (valarray_array.h:71)
==2258==    by 0x437D66: trans(int) (transFile.cpp:64)
==2258==    by 0x413B0E: membrane::MCstep(int) (membrane.cpp:490)
==2258==    by 0x402767: main (main.cpp:14)
==2258==
==2258== Invalid read of size 8
==2258==    at 0x439240: trans(int) (stl_vector.h:604)
==2258==    by 0x413B0E: membrane::MCstep(int) (membrane.cpp:490)
==2258==    by 0x402767: main (main.cpp:14)
==2258==  Address 0x111 is not stack'd, malloc'd or (recently) free'd
==2258==
==2258==
==2258== Process terminating with default action of signal 11 (SIGSEGV)
==2258==  Access not within mapped region at address 0x111
==2258==    at 0x439240: trans(int) (stl_vector.h:604)
==2258==    by 0x413B0E: membrane::MCstep(int) (membrane.cpp:490)
==2258==    by 0x402767: main (main.cpp:14)
==2258==  If you believe this happened as a result of a stack
==2258==  overflow in your program's main thread (unlikely but
==2258==  possible), you can try to increase the size of the
==2258==  main thread stack using the --main-stacksize= flag.
==2258==  The main thread stack size used in this run was 10485760.

I believe that the problem is that I’m not careful enough when I try to delete/put a bead into a vector and this is why I want to move to set.

  • 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-24T20:18:35+00:00Added an answer on May 24, 2026 at 8:18 pm

    That depends on what you want to achieve. Your code will most definitely compile if you remove fooBoxes[i][j][k].resize(0); since the std::set does not support this function.

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

Sidebar

Related Questions

Suppose I have this (C++ or maybe C) code: vector<int> my_vector; for (int i
I have a method defined in an unmanaged DLL: int foo(somestruct * vector, int
In my code, I have a vector <vector <vector <vector <std::tr1::shared_ptr<foo> > > >
I have the following code: void foo() { vector<double> v(100,1); // line 1 //
If I have the following code, Foo *f = new Foo(); vector<Foo*> vect; vect.push_back(f);
I have a 3D vector defined like this... std::vector<std::vector<std::list<Object*> > > m_objectTiles; I have
hey, I have this code that should save a java.util.Vector of custom serializable classes:
I have defined two dimensional array using following definition typedef std::vector<std::vector<short> > table_t; Can
I have a Vector that holds a number of objects. My code uses a
Say, I have a std::vector<SomeClass *> v; in my code and I need to

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.