liveBook · Manning

First-in-last-out structure

As explained in High Performance Unity Game Development

An ordering discipline in which the most recently added item is the first removed.

A first-in-last-out (LIFO) structure removes the most recently added item first. Stack storage follows this order, supporting contiguous data and automatic deallocation when data goes out of scope. Heap allocations do not necessarily follow LIFO order, and freeing them can leave unusable gaps. section 2.8 section 3.1

Heap holes

Allocate arrays of 1 KB, 2 KB, and 1 KB, then delete the first and third. Although 2 KB is free in total, the two separate 1 KB holes cannot hold a 1.5 KB array. section 3.1

Figure 3.4 We have 2048 bytes of memory free, but if we try to allocate an array of 1536 bytes, we’ll run out of memory because the biggest contiguous space is 1024 bytes.

Shows how fragmented free space can prevent a large allocation even when total free memory is sufficient. section 3.1

How High Performance Unity Game Development covers it

How deep it goes
Defines stack storage as LIFO, contrasts heap fragmentation, and notes that Unity's garbage collector can fragment memory even with reverse-order deallocation.
Examples
Uses three differently sized arrays to show how two separate free holes block a larger allocation.
What you can do after
Understand why fragmented free memory can prevent an allocation despite sufficient total space.
How it connects
Connects stack allocation, heap allocation, data locality, and memory fragmentation.

Also explained in

Compare how 3 books explain first-in-last-out structure →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of High Performance Unity Game Development. The section links point to the parts of the book it draws on.