Align memory.
More...
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include "is_pow2.h"
Go to the source code of this file.
|
static void * | align (const size_t alignment, const size_t size, void **ptr_ptr, size_t *space_ptr) |
| Align pointer to the next alignment boundary.
|
|
static uintptr_t | calc_alignment_padding (const size_t alignment, const uintptr_t ptr) |
| Calculate the alignment padding required to align a pointer.
|
|
Align memory.
This is a direct translation of the std::align implementation in libstdc++.
See:
◆ CALC_ALIGNMENT_PADDING
#define CALC_ALIGNMENT_PADDING |
( |
| alignment, |
|
|
| ptr ) |
Value:((((ptr) - 1u + (alignment)) & -(alignment)) - (ptr))
compile time calc_alignment_padding
.
◆ align()
static void * align |
( |
const size_t | alignment, |
|
|
const size_t | size, |
|
|
void ** | ptr_ptr, |
|
|
size_t * | space_ptr ) |
|
inlinestatic |
Align pointer to the next alignment boundary.
- Parameters
-
[in] | alignment | The desired alignment. |
[in] | size | The size of the storage to be aligned. |
[in,out] | ptr_ptr | Pointer to contiguous storage (a buffer) of at least space bytes. Given it's pointer. |
[in,out] | space_ptr | The size of the buffer in which to operate. Given it's pointer. |
- Returns
- The adjusted value of
*ptr_ptr
.
- Return values
-
NULL | If the space provided is too small. |
◆ calc_alignment_padding()
static uintptr_t calc_alignment_padding |
( |
const size_t | alignment, |
|
|
const uintptr_t | ptr ) |
|
inlinestatic |
Calculate the alignment padding required to align a pointer.
- Parameters
-
[in] | alignment | The desired alignment. |
[in] | ptr | Pointer to a buffer as uintptr_t . |
- Returns
- The padding to be added to
ptr
to align ptr
.