siplasplas
A library for C++ reflection and introspection
|
Tools related to raw memory manipulation. More...
Typedefs | |
using | cpp::detail::AlignedMallocAlingOffset = std::uint8_t |
Type used to store the offset between the aligned pointer returned by aligned_malloc() and the beginning of the allocated block. More... | |
Functions | |
SIPLASPLAS_UTILITY_EXPORT char * | cpp::detail::aligned_ptr (char *pointer, std::size_t alignment) |
Returns an address aligned to an specific boundary. More... | |
SIPLASPLAS_UTILITY_EXPORT void * | cpp::detail::aligned_ptr (void *pointer, std::size_t alignment) |
Returns an address aligned to an specific boundary. More... | |
SIPLASPLAS_UTILITY_EXPORT const char * | cpp::detail::aligned_ptr (const char *pointer, std::size_t alignment) |
Returns an address aligned to an specific boundary. More... | |
SIPLASPLAS_UTILITY_EXPORT const void * | cpp::detail::aligned_ptr (const void *pointer, std::size_t alignment) |
Returns an address aligned to an specific boundary. More... | |
SIPLASPLAS_UTILITY_EXPORT bool | cpp::detail::is_aligned (char *pointer, std::size_t alignment) |
Checks if an address is aligned to a given boundary. More... | |
SIPLASPLAS_UTILITY_EXPORT bool | cpp::detail::is_aligned (void *pointer, std::size_t alignment) |
Checks if an address is aligned to a given boundary. More... | |
SIPLASPLAS_UTILITY_EXPORT bool | cpp::detail::is_aligned (const char *pointer, std::size_t alignment) |
Checks if an address is aligned to a given boundary. More... | |
SIPLASPLAS_UTILITY_EXPORT bool | cpp::detail::is_aligned (const void *pointer, std::size_t alignment) |
Checks if an address is aligned to a given boundary. More... | |
SIPLASPLAS_UTILITY_EXPORT std::uintptr_t | cpp::detail::missalignment (const char *address, std::size_t alignment) |
Returns the distance between a memory address and the next address aligned to the given boundary. More... | |
SIPLASPLAS_UTILITY_EXPORT std::uintptr_t | cpp::detail::missalignment (const void *address, std::size_t alignment) |
Returns the distance between a memory address and the next address aligned to the given boundary. More... | |
SIPLASPLAS_UTILITY_EXPORT std::uintptr_t | cpp::detail::missalignment (char *address, std::size_t alignment) |
Returns the distance between a memory address and the next address aligned to the given boundary. More... | |
SIPLASPLAS_UTILITY_EXPORT std::uintptr_t | cpp::detail::missalignment (void *address, std::size_t alignment) |
Returns the distance between a memory address and the next address aligned to the given boundary. More... | |
template<typename T , typename U > | |
T * | cpp::detail::tagPointer (T *pointer, U data) |
Tags a pointer with the specified data. More... | |
template<typename R , typename U , typename... Args> | |
auto | cpp::detail::tagPointer (R(*pointer)(Args...), U data) -> decltype(pointer) |
Tags a pointer with the specified data. More... | |
template<typename T > | |
T * | cpp::detail::untagPointer (T *pointer) |
Untags a pointer. More... | |
template<typename R , typename... Args> | |
auto | cpp::detail::untagPointer (R(*pointer)(Args...)) -> decltype(pointer) |
Untags a pointer. More... | |
template<typename T > | |
std::uint16_t | cpp::detail::readTaggedPointer (T *pointer) |
Reads the data stored in a tagged pointer. More... | |
template<typename R , typename... Args> | |
std::uint16_t | cpp::detail::readTaggedPointer (R(*pointer)(Args...)) |
Reads the data stored in a tagged pointer. More... | |
SIPLASPLAS_UTILITY_EXPORT void * | cpp::detail::aligned_malloc (std::size_t size, std::size_t alignment, std::size_t offset=0) |
Allocates a block of memory of memory aligned to an specific boundary. More... | |
SIPLASPLAS_UTILITY_EXPORT void * | cpp::detail::aligned_malloc_block (void *pointer, std::size_t offset=0) |
Returns a pointer to the full block allocated by cpp::aligned_malloc() More... | |
SIPLASPLAS_UTILITY_EXPORT void | cpp::detail::aligned_free (void *pointer, std::size_t offset=0) |
Deallocates a block allocated by cpp::aligned_malloc() More... | |
Tools related to raw memory manipulation.
using cpp::detail::AlignedMallocAlingOffset = typedef std::uint8_t |
Type used to store the offset between the aligned pointer returned by aligned_malloc() and the beginning of the allocated block.
This type limits the maximum alignment requirement that can be passed to aligned_malloc() stores the distance to the start of the allocated block so it can be deallocated in aligned_free(). To use as little extra memory as possible, a 8 bit unsigned integer is used by default, which means up to 256 byte alignment boundary is supported by default. Users can change that limit by defining SIPLASPLAS_UTILITY_ALIGNEDMALLOC_ALIGNOFFSET_BITS
to the with in bits of the unsigned integer used for offset storage (8, 16, 32, and 64 are supported)
SIPLASPLAS_UTILITY_EXPORT void cpp::detail::aligned_free | ( | void * | pointer, |
std::size_t | offset = 0 |
||
) |
Deallocates a block allocated by cpp::aligned_malloc()
pointer | Pointer to the allocated block |
offset | User offset. The behavior is undefined if it's different to the argument given to cpp::aligned_malloc() when allocating the block |
SIPLASPLAS_UTILITY_EXPORT void* cpp::detail::aligned_malloc | ( | std::size_t | size, |
std::size_t | alignment, | ||
std::size_t | offset = 0 |
||
) |
Allocates a block of memory of memory aligned to an specific boundary.
This function allocates a memory block starting at a specific alignment boundary. Users can also set some extra bytes for bookeeping data before the returned block. To deallocate blocks allocated with aligned_malloc(), use aligned_free(), never std::free()
size | Requested block size in bytes |
alignment | Required alignment boundary. Must be a power of two |
offset | Extra space reserved for the user right brefore the returned block. 0 by default. |
size
bytes, multiple of alignment
. nullptr if fails SIPLASPLAS_UTILITY_EXPORT void* cpp::detail::aligned_malloc_block | ( | void * | pointer, |
std::size_t | offset = 0 |
||
) |
Returns a pointer to the full block allocated by cpp::aligned_malloc()
aligned_malloc() allocates an oversized block in order to acomplish the alignment requirements While aligned_malloc() returns the expected aligned block, this function can be used to get the complete allocated block.
pointer | Pointer to a block allocated by cpp::aligned_malloc() |
offset | User offset. The behavior is undefined if it's different to the argument given to cpp::aligned_malloc() when allocating the block |
std::free()
. SIPLASPLAS_UTILITY_EXPORT char* cpp::detail::aligned_ptr | ( | char * | pointer, |
std::size_t | alignment | ||
) |
Returns an address aligned to an specific boundary.
pointer | Starting address |
alignment | Alignment boundary. Must be a power of two |
SIPLASPLAS_UTILITY_EXPORT void* cpp::detail::aligned_ptr | ( | void * | pointer, |
std::size_t | alignment | ||
) |
Returns an address aligned to an specific boundary.
pointer | Starting address |
alignment | Alignment boundary. Must be a power of two |
SIPLASPLAS_UTILITY_EXPORT const char* cpp::detail::aligned_ptr | ( | const char * | pointer, |
std::size_t | alignment | ||
) |
Returns an address aligned to an specific boundary.
pointer | Starting address |
alignment | Alignment boundary. Must be a power of two |
SIPLASPLAS_UTILITY_EXPORT const void* cpp::detail::aligned_ptr | ( | const void * | pointer, |
std::size_t | alignment | ||
) |
Returns an address aligned to an specific boundary.
pointer | Starting address |
alignment | Alignment boundary. Must be a power of two |
SIPLASPLAS_UTILITY_EXPORT bool cpp::detail::is_aligned | ( | char * | pointer, |
std::size_t | alignment | ||
) |
Checks if an address is aligned to a given boundary.
pointer | Address to check |
alignment | Required alignment. Must be a power of two |
pointer
is aligned to alignment
boundary. False otherwise. SIPLASPLAS_UTILITY_EXPORT bool cpp::detail::is_aligned | ( | void * | pointer, |
std::size_t | alignment | ||
) |
Checks if an address is aligned to a given boundary.
pointer | Address to check |
alignment | Required alignment. Must be a power of two |
pointer
is aligned to alignment
boundary. False otherwise. SIPLASPLAS_UTILITY_EXPORT bool cpp::detail::is_aligned | ( | const char * | pointer, |
std::size_t | alignment | ||
) |
Checks if an address is aligned to a given boundary.
pointer | Address to check |
alignment | Required alignment. Must be a power of two |
pointer
is aligned to alignment
boundary. False otherwise. SIPLASPLAS_UTILITY_EXPORT bool cpp::detail::is_aligned | ( | const void * | pointer, |
std::size_t | alignment | ||
) |
Checks if an address is aligned to a given boundary.
pointer | Address to check |
alignment | Required alignment. Must be a power of two |
pointer
is aligned to alignment
boundary. False otherwise. SIPLASPLAS_UTILITY_EXPORT std::uintptr_t cpp::detail::missalignment | ( | const char * | address, |
std::size_t | alignment | ||
) |
Returns the distance between a memory address and the next address aligned to the given boundary.
address | Memory address |
alignment | Required alignment. Must be a power of two |
SIPLASPLAS_UTILITY_EXPORT std::uintptr_t cpp::detail::missalignment | ( | const void * | address, |
std::size_t | alignment | ||
) |
Returns the distance between a memory address and the next address aligned to the given boundary.
address | Memory address |
alignment | Required alignment. Must be a power of two |
SIPLASPLAS_UTILITY_EXPORT std::uintptr_t cpp::detail::missalignment | ( | char * | address, |
std::size_t | alignment | ||
) |
Returns the distance between a memory address and the next address aligned to the given boundary.
address | Memory address |
alignment | Required alignment. Must be a power of two |
SIPLASPLAS_UTILITY_EXPORT std::uintptr_t cpp::detail::missalignment | ( | void * | address, |
std::size_t | alignment | ||
) |
Returns the distance between a memory address and the next address aligned to the given boundary.
address | Memory address |
alignment | Required alignment. Must be a power of two |
std::uint16_t cpp::detail::readTaggedPointer | ( | T * | pointer | ) |
Reads the data stored in a tagged pointer.
Assuming the pointer is a tagged pointer, this function reads the data tagged in the 16 more significative bits of the pointer. Compilation fails if this function is used in non 64 bit architectures.
pointer | Tagged pointer to read |
std::uint16_t cpp::detail::readTaggedPointer | ( | R(*)(Args...) | pointer | ) |
Reads the data stored in a tagged pointer.
Assuming the pointer is a tagged pointer, this function reads the data tagged in the 16 more significative bits of the pointer. Compilation fails if this function is used in non 64 bit architectures.
pointer | Tagged pointer to read |
T* cpp::detail::tagPointer | ( | T * | pointer, |
U | data | ||
) |
Tags a pointer with the specified data.
This function uses the tagged pointer technique to store data in a 64 bit virtual memory address. Passing data of more than 16 bits wide has undefined behavior. Compilation fails if this function is used in non 64 bit architectures. Note accessing a tagged pointer directly may cause a segmentation fault. See cpp::untagPointer().
T | Pointed type |
U | Must be an integral type of max sizeof(U) = 16 bit |
pointer | pointer where to store data |
data | data to store |
auto cpp::detail::tagPointer | ( | R(*)(Args...) | pointer, |
U | data | ||
) | -> decltype(pointer) |
Tags a pointer with the specified data.
This function uses the tagged pointer technique to store data in a 64 bit virtual memory address. Passing data of more than 16 bits wide has undefined behavior. Compilation fails if this function is used in non 64 bit architectures. Note accessing a tagged pointer directly may cause a segmentation fault. See cpp::untagPointer().
U | Must be an integral type of max sizeof(U) = 16 bit |
pointer | pointer where to store data |
data | data to store |
T* cpp::detail::untagPointer | ( | T * | pointer | ) |
Untags a pointer.
Assuming the pointer is a tagged pointer, this function removes the tagged data and returns the memory address ready to be referenced. Compilation fails if this function is used in non 64 bit architectures.
pointer | Tagged pointer to clear |
auto cpp::detail::untagPointer | ( | R(*)(Args...) | pointer | ) | -> decltype(pointer) |
Untags a pointer.
Assuming the pointer is a tagged pointer, this function removes the tagged data and returns the memory address ready to be referenced. Compilation fails if this function is used in non 64 bit architectures.
pointer | Tagged pointer to clear |