Allocation¶
Alloc¶
Allocates a block of memory.
Parameters¶
| Parameter | Description |
|---|---|
size |
Number of bytes to allocate. |
Return Value¶
Returns a pointer to the allocated memory block.
Returns null if allocation fails.
Example¶
Realloc¶
Resizes a previously allocated memory block.
Parameters¶
| Parameter | Description |
|---|---|
ptr |
Existing memory block. |
size |
New size in bytes. |
Return Value¶
Returns a pointer to the resized memory block.
Notes¶
- Existing contents are preserved up to the smaller of the old and new sizes.
- Passing
nullbehaves likeAlloc(). - Passing
0frees the memory and returnsnull.
Example¶
Free¶
Releases memory previously allocated by Alloc() or Realloc().
Example¶
Notes¶
- Passing
nullis allowed. - Accessing memory after it has been freed is undefined behavior.