So, let's summarize the key points regarding usage of the malloc(3) API:
- malloc(3) dynamically (at runtime) allocates memory from the process heap
- As we shall soon learn, this is not always the case
- The single parameter to malloc(3) is an unsigned integer value—the number of bytes to allocate
- The return value is a pointer to the start of the newly allocated memory chunk on success, or NULL on failure:
- You must check for the failure case; don't just assume it will succeed
- malloc(3) always returns a memory region that is aligned on an 8-byte boundary
- The content of the newly allocated memory region is considered to be random
- You must initialize it before reading from any part of it
- You must free the memory you allocate