TRLC Platform Library
1.0.0
Header-only C++ library for compile-time platform detection and abstraction
|
Compile-time type and alignment information utilities. More...
#include <cstddef>
#include <type_traits>
#include <cstdint>
Go to the source code of this file.
Classes | |
struct | trlc::platform::TypeInfo< Type > |
struct | trlc::platform::AlignedType< TAlignment > |
Namespaces | |
trlc | |
trlc::platform | |
trlc::platform::detail | |
Macros | |
#define | TRLC_ALIGNOF(type) (alignof(type)) |
Get the alignment of a type. More... | |
#define | TRLC_SIZEOF(type) (sizeof(type)) |
Get the size of a type. More... | |
#define | TRLC_CACHE_LINE_SIZE (trlc::platform::getCacheLineSize()) |
Get the cache line size for the current platform. More... | |
#define | TRLC_PAGE_SIZE (trlc::platform::getPageSize()) |
Get the page size for the current platform. More... | |
#define | TRLC_ALIGN_TO_CACHE_LINE alignas(trlc::platform::getCacheLineSize()) |
#define | TRLC_ALIGN_TO_PAGE alignas(trlc::platform::getPageSize()) |
Align a type to page boundaries. More... | |
#define | TRLC_PAGE_ALIGNED(type, name) TRLC_ALIGN_TO_PAGE type name |
Create a cache-line aligned variable. More... | |
Typedefs | |
using | trlc::platform::CacheLineAligned = AlignedType< 64 > |
using | trlc::platform::PageAligned = AlignedType< 4096 > |
Functions | |
static size_t | trlc::platform::detail::detectPageSize () |
Detect page size (implementation detail) More... | |
template<typename Type > | |
static size_t | trlc::platform::detail::calculateTypePadding () |
Calculate padding for a type (implementation detail) More... | |
template<typename Type > | |
static bool | trlc::platform::detail::hasTypePadding () |
Check if a type has padding (implementation detail) More... | |
template<typename Type > | |
static size_t | trlc::platform::getTypeSize () |
template<typename Type > | |
static size_t | trlc::platform::getTypeAlignment () |
static size_t | trlc::platform::getCacheLineSize () |
Get the cache line size for the current platform. More... | |
static size_t | trlc::platform::getPageSize () |
Get the page size for the current platform. More... | |
template<typename Type > | |
static size_t | trlc::platform::calculatePadding () |
template<typename Type > | |
static bool | trlc::platform::hasInternalPadding () |
template<typename Type , size_t TExpectedSize> | |
static bool | trlc::platform::verifyTypeSize () |
template<typename Type , size_t TExpectedAlignment> | |
static bool | trlc::platform::verifyTypeAlignment () |
template<typename Type > | |
static bool | trlc::platform::isCacheLineAligned () |
Verify that a type is suitably aligned for cache line optimization. More... | |
template<typename Type > | |
static bool | trlc::platform::isPageAligned () |
Verify that a type is suitably aligned for page boundaries. More... | |
static size_t | trlc::platform::alignedSize (size_t size, size_t alignment) |
Calculate the aligned size for a given alignment. More... | |
static uintptr_t | trlc::platform::alignedAddress (uintptr_t addr, size_t alignment) |
Calculate the aligned address for a given alignment. More... | |
static bool | trlc::platform::isAligned (uintptr_t addr, size_t alignment) |
Check if an address is aligned to the specified boundary. More... | |
bool | trlc::platform::isAligned (const void *ptr, size_t alignment) |
Check if a pointer is aligned to the specified boundary. More... | |
Compile-time type and alignment information utilities.
This header provides comprehensive type introspection and memory layout utilities for C++ types. It includes compile-time type size and alignment queries, padding analysis, cache line and page alignment helpers, and type verification utilities.
Features:
All utilities are designed to work at compile time when possible, providing zero runtime overhead for type introspection and memory layout analysis.
Definition in file typeinfo.hpp.
#define TRLC_ALIGN_TO_CACHE_LINE alignas(trlc::platform::getCacheLineSize()) |
Definition at line 585 of file typeinfo.hpp.
#define TRLC_ALIGN_TO_PAGE alignas(trlc::platform::getPageSize()) |
Align a type to page boundaries.
This macro can be used to align variables, struct members, or entire types to page boundaries for memory management optimizations.
Definition at line 593 of file typeinfo.hpp.
#define TRLC_ALIGNOF | ( | type | ) | (alignof(type)) |
Get the alignment of a type.
This macro provides a convenient way to get type alignment. It's equivalent to alignof(type) but matches the naming convention.
Definition at line 546 of file typeinfo.hpp.
#define TRLC_CACHE_LINE_SIZE (trlc::platform::getCacheLineSize()) |
Get the cache line size for the current platform.
This macro provides compile-time access to the cache line size.
Definition at line 561 of file typeinfo.hpp.
#define TRLC_PAGE_ALIGNED | ( | type, | |
name | |||
) | TRLC_ALIGN_TO_PAGE type name |
Create a cache-line aligned variable.
This macro declares a variable that is aligned to cache line boundaries.
type | The type of the variable |
name | The name of the variable |
Create a page-aligned variable
This macro declares a variable that is aligned to page boundaries.
type | The type of the variable |
name | The name of the variable |
Definition at line 613 of file typeinfo.hpp.
#define TRLC_PAGE_SIZE (trlc::platform::getPageSize()) |
Get the page size for the current platform.
This macro provides compile-time access to the page size.
Definition at line 568 of file typeinfo.hpp.
#define TRLC_SIZEOF | ( | type | ) | (sizeof(type)) |
Get the size of a type.
This macro provides a convenient way to get type size. It's equivalent to sizeof(type) but matches the naming convention.
Definition at line 554 of file typeinfo.hpp.