Dynamic Memory Allocation: Advanced Concepts

References

Review: Dynamic Memory Allocation

Review: Keeping Track of Free Blocks

Review: Implicit Lists Summary

Explicit Free Lists

Freeing With Explicit Free Lists

Freeing with a LIFO Policy

An Implementation Trick

Explicit List Summary

Segregated List (Seglist) Allocators

Seglist Allocator

Seglist Allocator (Continued)

Dereferencing Bad Pointers

Reading Uninitialized Memory

Overwriting Memory

Overwriting Memory

Overwriting Memory

Overwriting Memory

Overwriting Memory

Referencing Nonexistent Variables

Freeing Blocks Multiple Times

x = malloc(N*sizeof(int));
      <manipulate x>
free(x);

y = malloc(M*sizeof(int));
        <manipulate y>
free(x);

Referencing Freed Blocks

x = malloc(N*sizeof(int));
  <manipulate x>
free(x);
   ...
y = malloc(M*sizeof(int));
for (i=0; i<M; i++)
   y[i] = x[i]++;

Failing to Free Blocks (Memory Leaks)

foo() {
   int *x = malloc(N*sizeof(int));
   ...
   return;
}

Failing to Free Blocks (Memory Leaks)

Dealing With Memory Bugs

Implicit Memory Management: Garbage Collection

Garbage Collection

Classical Garbage Collection Algorithms

Memory as a Graph

Memory as a Graph

Mark and Sweep Collecting

Assumptions for a Simple Implementation

Mark and Sweep Pseudocode

Mark and Sweep Pseudocode

Conservative Mark and Sweep in C