Are global structures distributed on the stack or on the heap?

I write in an environment where I am not allowed to allocate new memory after starting the program, and I cannot make operating system calls. When tracking a page error error (probably caused by an unintentional violation of one of the above), a question arises with me (since this is a bit of me in the butt with std lines)

Is the global / local structure distributed on the stack or heap? For instance:

If this operator is in the global scope

struct symbol { char blockID; int blockNum; int ivalue; double fvalue; int reference; bool isFloat, isInt, isRef; int symbolLength; } mySymbol; 

where is the allocated memory located?

+4
source share
2 answers

It is defined according to the implementation (the C ++ standard does not talk about the stack and heap).

As a rule, objects with static storage duration (such as global ones) will fall into a special segment of the address space, which is neither a stack nor a heap. But features vary from platform to platform.

+6
source

In C ++, unlike C #, a struct makes several differences with class . A struct is a class by default whose visibility is public. Whether distribution is on the stack or on the heap depends on how you place your instance

 class A; void f() { A a;//stack allocated A *a1 = new A();// heap } 
+6
source

All Articles