What does the Data area contain ?

Hi there!

According to this:

---> http://en.wikipedia.org/wiki/Data_segment

RAM area contains:

* Data Segment (Data + BSS + Heap)
* Stack

In detail:

* The Data area contains global variables used by the program that are not initialized to zero.


But the Data area doesn't contain only global variables. It contains static variables too, right ?

Thx for your help :P
No.

Static variables can be dynamically allocated which by definition means they exist on the heap. And they can be on the Data Segment when not dynamic and initialized. The term perhpas is you are confusing is const?

Static defines scope (lifetime of the variable) and not necessarily the area of allocation of the variable.

Edit...grr... you made me research this... :)

http://en.wikipedia.org/wiki/Static_memory_allocation

Its compile time allocated.
Last edited on
Static variables can be dynamically allocated which by definition means they exist on the heap.


Sorry but I don't understand. Static variables can be dynamically allocated ?

So, according to you, something like this:

1
2
3
4
void fun()
{
    int* ptr = new static int;
}


is correct ?
absolutely not... I meant and fumbled at it, was the static can point to heap allocated memory
1
2
3
static int* i;

i = new int(0);


The pointer is not allocated on the heap but the object pointed to (which is ratained due to the static nature) is on the heap.
The pointer is not allocated on the heap


exactly...

Then why do you think that "Static variables can be dynamically allocated" ?
What part of my response was unclear?

absolutely not... I meant and fumbled at it, was the static can point to heap allocated memory

The pointer is not allocated on the heap but the object pointed to (which is ratained due to the static nature) is on the heap.


Which followed the previous statement of:
Edit...grr... you made me research this... :)

http://en.wikipedia.org/wiki/Static_memory_allocation

Its compile time allocated.
Last edited on
Topic archived. No new replies allowed.