Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > storage locations for different data types
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 28th September 18:22
External User
 
Posts: 1
Default storage locations for different data types



In the standard. In practice, heap and stack are usable
synonyms.

Let's not forget, either, that the compiler is not required to
use a contiguous area for any of these. It could very well use
different areas for operator new, operator new[] and malloc, for
example, or allocate stack frames dynamically from the same pool
that malloc uses. (I've actually used a C compiler which did this.)

Typically, the compiler will manage two separate "static"
areas, one of which will be write protected when your program
executes (and probably shared amongst multiple instances which execute simutaneously).

With the compilers I use, it depends on the type of the object.
If the object has dynamic initialization or a non-trivial
destructor, it will be allocated with the other static objects.
If it is statically initialized, it will normally be allocated
in the write protected part of the static memory. And if it is
simple enough, and its address is never taken, it might not be allocated at all.


With the same caveats as above.


If the type is simple enough, and the address of the object is
never taken, the object probably will not be allocated at all.
Otherwise, if the object is initialized with a constant
expression, and has a trivial constructor and destructor, it
will most likely be allocated in the write protected static
memory -- most likely, because if the address of the object is
taken, and the function is called recursively, this cannot be
done, since the addresses have to differ.

With all of the above caveats, of course.

And of course, we're only considering single threaded programs
without dynamically loaded objects here.

In fact, of course, the correct answer for all of the above
questions is really: where ever the compiler wants:-).

--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
  Reply With Quote


 


Reply


Thread Tools
Display Modes




666