В моем коде я определил вектор:
vector<vector<vector<vector<shared_ptr<foo> > > > > fooBoxes;
Я инициализирую вектор, используя:
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);
}
}
}
Я подозреваю, что использование вектора вызывает ошибку сегментации, и я хочу заменить fooBoxes
на:
vector<vector<vector<set<shared_ptr<foo> > > > > fooBoxes
что мне делать в for
циклах? просто удалите resize(0)
часть?
Edit:
Это вывод valgrind в аварии:
==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.
Я считаю, что проблема в том, что я недостаточно осторожен, когда пытаюсь удалить / поместить бусину в вектор, и поэтому я хочу перейти к установке.