Karten 12 Karten
Lernende 0 Lernende
Sprache English
Stufe Universität
Erstellt / Aktualisiert 25.06.2019 / 25.06.2019
Lizenzierung Keine Angabe
0 Exakte Antworten 12 Text Antworten 0 Multiple Choice Antworten
Fenster schliessen

What is the heap?

  • malloc() allocations
    • Fullfill allocating and deallocating of memory regions
  • Dynamic memory (allocations at runtime)
  • What is on the heap:
    • Objects, big buffers, structs, persistence, large things
  • Its slow, manually
Fenster schliessen

What do the functions malloc() and free() do?

  • malloc(): get a memory region
  • free(): release a memory region
Fenster schliessen

How does the heap work?

void *ptr;

ptr = malloc(len)

  • Allocated "len" size memory block
  • Returns a pointer to this memory block


  • Tells the memory allocator that the memory block can now be re-used
  • Note: ptr is NOT NULL after free()
Fenster schliessen

What does the heap allocator do?

the heap allocator does:

  • allocate big memory pages from the OS
  • Mange these pages
  • Split the pages into smaller chunks
  • Make these chunks available to the program
Fenster schliessen

Where is the heap relative to the stack, and in what direction does it grow?

Lizenzierung: Keine Angabe
Fenster schliessen

How are memory pages brocken down in the heap?

Lizenzierung: Keine Angabe
Fenster schliessen

How does the memory management work?

Lizenzierung: Keine Angabe

Heap allocator requierments:

  • Shoul be quick to fulfill malloc() and free()
  • Shoul not wast memory by managing memory

Example PHP7 emalloc:

  • First chunk has management information
  • Management chunk describes other chunks
  • Which are free, how big they are etc ...
Fenster schliessen

What is at the top of the chunk when it is allocate and unalocated

Lizenzierung: Keine Angabe

Allocated chunk:

  • Size of previous chunk
  • Size of chunk

Free chunk:

  • Size of previous chunk
  • Size of chunk
  • Forward pointer to next chunk
  • Back pointer to previous chunk