> For the complete documentation index, see [llms.txt](https://computerscienceeducation.gitbook.io/co-lab-manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://computerscienceeducation.gitbook.io/co-lab-manual/reference-documentation/memory.md).

# Memory

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

<div align="center"><figure><picture><source srcset="/files/PewTWUyoIa1v9eoJESxh" 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](/co-lab-manual/assignments/extra-assignments/a3-b-fibonacci-repl.md).
* 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 ](/co-lab-manual/assignments/mandatory-assignments/a2-subroutines-and-i-o.md)[1](/co-lab-manual/assignments/mandatory-assignments/a2-subroutines-and-i-o.md).
