Featured post
c++ stl vector causing memory overflow? -
i making extensive use of stl vectors manage memory (de-) allocation of large arrays of data. in particular generating perspective projections of anatomical structures large number of angles (180 in 2 degree steps), processing , analysing results. results used define radiation fields radiotherapy.
it seems if arrays exceed size (>3 anatomical structures) memory overflows. in particular error follows
terminate called after throwing instance of 'std::out_of_range' what(): vector::_m_range_check
this result of using at, bounds checking, rather faster [] operator. if have <=3 structures error not occur.
i have tracked error down following block of code
bool dicomcp::assignbeamlet(int beamletnumber, beamlet &b1) { //std::cout << "\ninside dicomcp::assignbeamlet (int, beamlet &)\n"; if (!this->isset) { this->beamlets.at(beamletnumber).setleftright(b1.left,b1.right); this->isset=true; return true; } else if (!this->beamlets.at(beamletnumber-1).isopen()) { return false; } // left (outside) min(left) , right (outside) max(right) leaves else if ((this->beamlets.at(beamletnumber-1).right-b1.left >epsilon2)&&(b1.right-this->beamlets.at(beamletnumber-1).left>epsilon2)) { if (this->beamlets.at(beamletnumber).open) return false; else if (!this->beamlets.at(beamletnumber).open) { this->beamlets.at(beamletnumber).setleftright(b1.left,b1.right); this->beamlets.at(beamletnumber).isassigned=true; this->isset=true; return true; } } else return false; }
note if "this->isset=true;" lines commented out error not manifest regardless of number of structures :yes works 6! "isset" boolean value used determine objects have been set, , hence objects need written out data file further processing.
system , sodtware:
gcc (suse linux) 4.4.1 [gcc-4_4-branch revision 150839] suse 11.2 64bit intel celsius 4 xeon 2.66ghz cpus , 4gb ram eclipse cdt (ide) 64 bit build 20100218-1602
apparently, accessing elements outside of container. it's impossible code, whether indexes correct or not, walk through code in debugger , see. suspicious looking piece: this->beamlets.at(beamletnumber-1).isopen()
if beamletnumber 0? invalid index.
- Get link
- X
- Other Apps
Comments
Post a Comment