Data Structures & Algorithms · Interview question

A pool allocator's alloc returns NULL. What does that mean and how do you handle it?

A strong answer

It means the pool is exhausted, all blocks are currently in use, because a pool is a fixed set of blocks with no ability to grow. Unlike desktop malloc returning NULL under genuine memory pressure (rare), pool exhaustion is a normal, expected condition you must design for. Handling depends on the data's semantics: for a packet buffer pool you might drop the incoming packet and increment a dropped-counter (and rely on the protocol's retransmission), or apply backpressure to the source; for a task pool you might reject the spawn and report an error; in a safety-critical path you fail safe to a known state. What you must not do is ignore the NULL and dereference it (an immediate crash) or block forever waiting for a free that may never come in an ISR. The pool size is a design parameter you set from worst-case concurrent usage plus margin, and the NULL path is the safety valve when reality exceeds the estimate.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Static vs Dynamic Allocation

How to give data structures memory on a constrained device: static arrays, fixed-block pools, and arena allocators, the O(1), fragmentation-free alternatives to general malloc.

More Static vs Dynamic Allocation questions

Browse all 472 interview questions
A pool allocator's alloc returns NULL. What does that mean and how do you handle it? | EmbeddedPrep.io