Home > programming > computer program memory

computer program memory

The computer program memory is organized into the following:

  • Data Segment (Data + BSS + Heap)
  • Stack
  • Code segment


  • Data

The data area contains global and static variables used by the program that are initialized. This segment can be further classified into initialized read-only area and initialized read-write area. For instance the string defined by char s[] = “hello world”; in C and a C statement like int debug=1; outside the main would be stored in initialized read-write area. And a C statement like char *string = “hello world”; makes the string literal “hello world” to be stored in initialized read-only area and the character pointer variable string in initialized read-write area. Ex: static int i = 10; will be stored in data segment and global int i = 10; will be stored in data segment

  • BSS

The BSS segment also colloquially known as uninitialized data starts at the end of the data segment and contains all global variables and static variables that are initialized to zero or do not have explicit initialization in source code. For instance a variable declared static int i; would be contained in the BSS segment.

  • Heap

The heap area begins at the end of the BSS segment and grows to larger addresses from there. The Heap area is managed by malloc, realloc, and free, which may use the brk and sbrk system calls to adjust its size (although, note that the use of brk/sbrk and a single “heap area” is not required to fulfil the contract of malloc/realloc/free; they may also be implemented using mmap to reserve potentially non-contiguous regions of virtual memory into the process’ virtual address space). The Heap area is shared by all shared libraries and dynamically loaded modules in a process.

  • Stack

The stack is a LIFO structure, typically located in the higher parts of memory. It usually “grows down” with every register, immediate value or stack frame being added to it. A stack frame consists at minimum of a return address.

Categories: programming
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: