Re: static, global variable memory allocation



Richard Tobin wrote, On 06/02/07 17:36:
In article <annm94xq6q.ln2@xxxxxxxxxxxxxxxxxxxxxxx>,
Flash Gordon <spam@xxxxxxxxxxxxxxxxxx> wrote:
My answer: static variable in function and global variable are
allocated in head, and automatic variable is allocated in stack.

In other words it depends entirely on the implementation but you are wrong for all the implementations I know of.

I think you must be interpreting "heap" in a narrow sense then.

Quite possible. This shows another problem in using terminology outside the standard without making it clear what you are referring to ;-)

> On
many unix implementations for example, the memory returned by malloc()
follows on directly from the area in which static data is stored, and
it is not unreasonable to use the term "heap" to refer to that entire
area. Presumably that is what the original poster had in mind.

I was now specifically aware of that, to be hones I gave up caring before I started programming on Unix, but given:
static const char var[]="Static array";
Would you expect var to be in that area you refer to as a heap or, as I would hope, in a separate memory region that was set to read only?

Also, I thought that it was common for the static/global data that is not const to be allocated in a bss (or similar) section that is defined as being zeroed and that historically at least the section the heap (as I would use the term) was allocated in would not since it did not need zeroing. Of course, I accept that security considerations could have made this academic.

In any case, note the weasel words "I know of" which can certainly be interpreted to mean the systems I know the details of, and thus as I was not aware of what you have said it was still accurate ;-)
--
Flash Gordon
.



Relevant Pages

  • Re: WTD: Bally Sling Backing Plate
    ... I'm fairly certain this style started with Flash Gordon and was used at least until Fireball Classic. ... Another thing is that some people refer to these as linear sling shot assys. ... on an embryon to, not sure which other games used it. ...
    (rec.games.pinball)
  • Re: static, global variable memory allocation
    ... Flash Gordon wrote: ... before I started programming on Unix, ... Would you expect var to be in that area you refer to as a heap or, as I would hope, in a separate memory region that was set to read only? ...
    (comp.lang.c)
  • Re: struct and union alignment
    ... > structs" was actually meant to refer to incomplete types, ... Flash Gordon ...
    (comp.lang.c)