liveBook · Manning

Vector

As explained in Modern C, Third Edition

A dynamic array is an array-like data structure whose storage can be allocated or resized during program execution.

A dynamic array allocates its storage during execution and can change capacity later. A circular buffer illustrates the design: elements append at the back, drop from the front, and remain bounded by configurable capacity. section 13.1.1

 struct circular {
   size_t  start [[deprecated("privat")]]; /* First element     */
   size_t  len   [[deprecated("privat")]]; /* Number of elements*/
   size_t  cap   [[deprecated("privat")]]; /* Maximum capacity  */
   double* tab   [[deprecated("privat")]]; /* Data array        */
 };

The structure separates logical state—start position, length, and capacity—from the allocated data array. section 13.1.1

Initialization and resizing

circular circ; circular_init(&circ, 100); /* append, remove, and access elements */ circular_resize(&circ, new_capacity); circular_destroy(&circ); section 13.1.1

Resizing may move the allocation, so callers must use the returned pointer. The implementation uses realloc and may copy or move wrapped regions with memcpy or memmove. section 13.1.1

How Modern C, Third Edition covers it

How deep it goes
Explains representation, initialization, destruction, access, resizing, allocation failure, and wrapped-data movement.
Examples
Demonstrates a double-valued circular buffer with initialization, element access, resizing, allocation failure, and destruction.
What it assumes
Assumes familiarity with C structures, pointers, arrays, allocation, and deallocation.
What you can do after
Builds a resizable circular buffer and preserves valid ownership across allocation, resizing, access, and destruction.
How it connects
Connects dynamic arrays with circular buffers, malloc, realloc, memcpy, memmove, and memory management.

Also explained in

Compare how 11 books explain vector →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.