liveBook · Manning

Malloc

malloc is a C standard-library function that allocates a specified number of bytes of uninitialized storage and returns a pointer to it or a null pointer if allocation fails.

How 2 Manning books explain it

Modern C, Third Edition

malloc is a C library function that allocates a specified number of bytes of uninitialized storage and returns a pointer to it or a null pointer on failure.

How it is used
Allocates storage for variable-sized arrays and circular buffers when fixed-size arrays are too restrictive.
How deep it goes
Works through sizing, failure checks, and release constraints without describing allocator internals.
Examples
Uses a variable-sized double array, a string-copying strdup sketch, and a resizable circular buffer.
What you can do after
Practice/perform variable-sized allocation with null checks, initialization, and matching deallocation.

Read how Modern C, Third Edition explains malloc →

Modern C

malloc is the C standard library function that allocates a specified number of bytes of storage and returns a pointer to the storage or a null pointer on failure.

How it is used
Deploys malloc for storage whose size or lifetime must vary during execution.
How deep it goes
Explains byte sizing, void pointers, allocation pairing, and valid free arguments, but defers implementation internals.
Examples
Uses a vector of doubles sized for one element per living person and examines platform feasibility.
What you can do after
Apply malloc to allocate byte-sized storage and maintain its lifetime with a valid matching free.

Read how Modern C explains malloc →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.