Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where are static buffers allocated?

Tags:

c

static

lets say I have a file test.c that contains:

char buffer1[1024];

int somefunction()
{
      char buffer2[1024];
      // do stuff
}

now I know buffer2 is allocated on the stack on the frame belonging to somefunction calls, but where is buffer1 allocated ?

like image 860
Oren Avatar asked Dec 24 '12 12:12

Oren


2 Answers

These variables are typically on BSS (variables which don't have explicit initialization in the source code, so they get the value 0 by default) or data segment (initialized datas). Here, buffer1 is uinitialized, so it will probably be allocated on BSS segment, which starts at the end of the data segment.

From bravegnu website:

enter image description here

like image 128
md5 Avatar answered Oct 09 '22 07:10

md5


buffer1 has memory reserved in the static(bss/data) memory section of the program. That's where all statics and globals exist.

It is a third memory segment, like the stack and the heap.

like image 34
StoryTeller - Unslander Monica Avatar answered Oct 09 '22 08:10

StoryTeller - Unslander Monica