Stack allocation is not performed, and heap allocation is successful! Is it possible?

I have the following snippet fragment

Class Sample
{ Obj_Class1 o1;
  Obj_Class2 o2;};

But the size Obj_Class1and Obj_Class2enormous, so the compiler shows warning "Consider the movement of a space in a heap." I was asked to replace Obj_Class1 o1 with Obj_Class1* o1 = new Obj_Class1();But I feel that using this change is not practical, as heap allocation will also fail if the stack allocation fails. I'm right? Or it makes sense to make this change (other than suppressing the compiler warning).

+5
source share
4 answers

, . . ( , ) . .

+5

, - .

, , Sample , :

int main() {
   Sample* sample = new Sample();
}
+3

: http://msdn.microsoft.com/en-us/library/ms686774(VS.85).aspx

. , . , , 1 . , STACKSIZE (.def). ( 64 ). , GetSystemInfo.

+3

In the case of visual studio, each thread by default receives 1 MB of space, and if you try to allocate more than you get an error. Heap does not have this limitation, and the amount of memory you can allocate depends on the largest contiguous space available in your process virtual memory. Therefore, it is not surprising that stack allocation fails if the objects are really huge.

+2
source

All Articles