What does the Data area contain ?
Jan 13, 2010 at 8:17pm UTC
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
Jan 13, 2010 at 8:40pm UTC
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 Jan 13, 2010 at 9:07pm UTC
Jan 13, 2010 at 9:41pm UTC
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 ?
Jan 13, 2010 at 10:03pm UTC
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.
Jan 13, 2010 at 10:14pm UTC
The pointer is not allocated on the heap
exactly...
Then why do you think that "Static variables can be dynamically allocated" ?
Jan 13, 2010 at 10:18pm UTC
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:
Last edited on Jan 13, 2010 at 10:18pm UTC
Topic archived. No new replies allowed.