C++ array causes crash if member of class -


i'm working particular library not built stl containers. in refactoring functions classes encountered stack overflow based on following pattern.

class base {     float values[1920 * 1080]; // causes overflow public:     base() {} };  int main() {     float values[1920 * 1080]; // not     base t; } 

i know may allocate dynamic memory base::values, why not cause stack overflow in main, in base, why stack space seem smaller base? perhaps it's obvious i'm missing.

(above example compiled using visual studio 2017, default flags)

1920 * 1080 * sizeof(float) sufficent blow stack. (8 mb)

ensure compiler not remove values array setting elements.

change base follows.

class base {     float * values;     base() {          values = new float[1920*1080];     }     ~base(){          delete [] values;     }  } 

also fix copy , assignment operators.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -