C8 Computer organization · Practice
Dynamic memory and linked structures
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
0 solved
0 in a row
0 of 8 kinds solid
Check
A bump allocator aligns to 8 bytes. How much space does a request for 9 bytes take?
Check
A node holds 8 bytes of data and a 4-byte pointer. The allocator adds an 8-byte header and rounds the total to a multiple of 16.
(a)
How many bytes does each node use?
(b)
What percentage of that is the data itself?
Check
Summing a 1000-node linked list costs a 50-cycle cache miss per node; summing an array of the same 1000 values costs one cycle per value. How many times longer does the list take?
Check
A heap is filled with 16 blocks of 64 bytes, and every second block is freed. How much memory is free in total?
Check
Three nodes are built at 0x1000, 0x1010 and 0x1008 (value, then link), linked in that order and ending with a 0 link. Starting from the head at 0x1000, count the nodes into a0 by following the links.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Write a first-fit allocator over a heap of H = 1024 bytes. alloc(n) rounds n up to 8, finds the lowest-addressed free block big enough, splits it, and returns the address (or None); release(addr) frees the block and merges it with free neighbors. Keep blocks as a sorted list of [addr, size, free]. Then run the workload: with rng = random.Random(seed), repeat 500 times: if rng.random() < 0.6, allocate rng.randrange(8, 129) bytes (record successes), else free a random live block (rng.randrange(len(live)), removing it from the list) if any. Set failures (failed allocations) and largest (the largest free block at the end).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
With 4-byte alignment, how many bytes does a 17-byte request occupy?
Check
Nodes hold 4 bytes of data, a 4-byte link and an 8-byte header (sizes already aligned). What percentage is data?
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C8