Allocating and initializing an object
rat const* myRat = rat_init(malloc(sizeof(rat)), 13, 7);\n\nHere, malloc obtains storage during execution, and rat_init explicitly puts that storage into a usable state. The storage remains available until it is released with free. section 13.4 section 13.1
Allocated storage duration is the C storage duration created explicitly by calls such as malloc and free. It supports collections whose size is known only during execution, including growing input, irregular data, large matrices, and streams. section 13.1 section 13.2
TAKEAWAY: An allocated object has a lifetime with a starting point and an endpoint. It cannot be accessed outside that lifetime; doing so has undefined behavior. Its lifetime is controlled explicitly rather than automatically determined by a declaration or function execution. section 13.2
The standard allocation interface separates several related operations:
- malloc obtains storage measured in bytes; sizeof *pointer keeps the requested size aligned with the pointer's type. section 13.1
- free releases storage that is no longer needed. section 13.1
- calloc provides a specialized allocation whose new storage has all bits set to 0; realloc grows or shrinks storage; aligned_alloc ensures nondefault alignment. section 13.1
- Allocated storage is not automatically initialized, so an object or array placed there needs explicit initialization, often through a type-specific _init function. section 13.4
Table 13.1. Storage classes, scope, linkage of identifiers, and storage duration of the associated objects Tentative indicates that a definition is implied only if there is no other definition with an initializer. Induced indicates that the linkage is internal if another declaration with internal linkage has been met prior to that declaration; otherwise, it is external. (view table figure)
Compare allocated duration with static, automatic, and thread storage durations, alongside scope, linkage, initialization, and lifetime. section 13.2

