# Memory

The memory of a running process is typically grouped into sections as shown below:

<div align="center"><figure><picture><source srcset="https://446709468-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkIfjAP0St3jlymiCJIij%2Fuploads%2Fgit-blob-ef131da89b39fb0c9e5fd7c0aeb6d86c5fe6536e%2Fmemory%20layout%20(dark).svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://446709468-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkIfjAP0St3jlymiCJIij%2Fuploads%2Fgit-blob-80bef3bc2449bfdd0203297743137174fa18a963%2Fmemory%20layout%20(light%2C%20filled).svg?alt=media" alt=""></picture><figcaption></figcaption></figure></div>

* The **Text** segment holds the program instructions as well as any read-only data (e.g., strings).
* The **Data** segment holds initialized data, so initialized global and static variables. Contrary to the text segment, this segment is not read-only, as the contents may be changed during execution.
* The **BSS** segment holds uninitialized data. The segment is initialized to zero before the program starts executing. It typically holds global or static variables that are either uninitialized or initialized to zero.
* The **Heap** memory is dynamically allocated program memory. It is managed through the `brk` and `sbrk` system calls, or, more commonly, through the suite of `malloc` library functions. Memory in this segment can be allocated and released at runtime.\
  You will need to work with heap memory in [Assignment 3-b](../assignments/extra-assignments/a3-b-fibonacci-repl).
* The **Stack** is a LIFO structure, growing from higher to lower addresses. It is used, among others, for local variables, return addresses, and temporary storage. The `rsp` register keeps track of the top of the stack, while the `rbp` register denotes the bottom of the current stack frame.\
  You will actively work with the stack starting from [Assignment ](../assignments/mandatory-assignments/a2-subroutines-and-i-o)[1](../assignments/mandatory-assignments/a2-subroutines-and-i-o).
