![]() |
|
Functions having to do with memory allocation/handling. More...
Files | |
| file | align.h |
| Provide architecture-specific memory-alignment information. | |
| file | mallocHook.h |
| Routines for controlling malloc behavior. | |
| file | prefetch.h |
| Memory prefetch. | |
Classes | |
| class | ArchMallocHook |
| Override default malloc() functionality. More... | |
Macros | |
| #define | ARCH_MAX_ALIGNMENT_INCREASE |
| Maximum extra space needed for alignment. | |
| #define | ARCH_CACHE_LINE_SIZE |
| The size of a CPU cache line on the current processor architecture in bytes. | |
Enumerations | |
| enum class | ArchPrefetchAccess { Read = 0 , Write = 1 } |
| The kind of access a prefetch is preparing for. More... | |
| enum class | ArchPrefetchLocality { None = 0 , L3 = 1 , L2 = 2 , L1 = 3 } |
| How much temporal locality you expect on the address after the fetch. More... | |
Functions | |
| size_t | ArchAlignMemorySize (size_t nBytes) |
| Return suitably aligned memory size. | |
| void * | ArchAlignMemory (void *base) |
| Align memory to the next "best" alignment value. | |
| ARCH_API void * | ArchAlignedAlloc (size_t alignment, size_t size) |
| Aligned memory allocation. | |
| ARCH_API void | ArchAlignedFree (void *ptr) |
| Free memory allocated by ArchAlignedAlloc. | |
| ARCH_API bool | ArchIsPtmallocActive () |
| Return true if ptmalloc is being used as the memory allocator. | |
| ARCH_API bool | ArchIsStlAllocatorOff () |
| Return true if the C++ STL allocator was requested to be turned off. | |
| template<size_t Size = 1, size_t Align = 1, ArchPrefetchAccess Access = ArchPrefetchAccess::Read, ArchPrefetchLocality Locality = ArchPrefetchLocality::L2> | |
| void | ArchPrefetch (void const *addr) noexcept |
Prefetch the cache lines that [addr, addr+Size) occupy. | |
| template<ArchPrefetchAccess Access = ArchPrefetchAccess::Read, ArchPrefetchLocality Locality = ArchPrefetchLocality::L2> | |
| void | ArchPrefetchRange (void const *addr, size_t numBytes) noexcept |
Prefetch the cache lines that [addr, addr+numBytes) occupy, where numBytes is a runtime value. | |
| template<ArchPrefetchAccess Access = ArchPrefetchAccess::Read, ArchPrefetchLocality Locality = ArchPrefetchLocality::L2, class T > | |
| void | ArchPrefetchRange (T const *addr, size_t count) noexcept |
Prefetch the cache lines that the count objects of type T starting at addr occupy, as in ArchPrefetchRange(vec.data(), vec.size()). | |
| template<ArchPrefetchLocality Locality = ArchPrefetchLocality::L2, class T > | |
| void | ArchPrefetchRead (T const *addr) noexcept |
Prefetch for reading the object at addr with given locality. | |
| template<ArchPrefetchLocality Locality = ArchPrefetchLocality::L2, class T > | |
| void | ArchPrefetchWrite (T const *addr) noexcept |
Prefetch for writing the object at addr with given locality. | |
Functions having to do with memory allocation/handling.
| #define ARCH_CACHE_LINE_SIZE |
| #define ARCH_MAX_ALIGNMENT_INCREASE |
Maximum extra space needed for alignment.
The ArchAlignMemorySize() can increase the required memory by no more than ARCH_MAX_ALIGNMENT_INCREASE.
|
strong |
The kind of access a prefetch is preparing for.
These follow gcc's __builtin_prefetch's 'rw' parameter. If you don't know what to use, just use Read. Most modern CPUs treat them the same regardless.
Definition at line 38 of file prefetch.h.
|
strong |
How much temporal locality you expect on the address after the fetch.
For pure-streaming, single access and done, use None. For a cache where you expect multiple repeat hits, use higher levels like L2 or L1.
Definition at line 46 of file prefetch.h.
| ARCH_API void * ArchAlignedAlloc | ( | size_t | alignment, |
| size_t | size ) |
Aligned memory allocation.
| ARCH_API void ArchAlignedFree | ( | void * | ptr | ) |
Free memory allocated by ArchAlignedAlloc.
|
inline |
|
inline |
Return suitably aligned memory size.
Requests to malloc() or ::new for a given size are often rounded upward. Given a request for nBytes bytes of storage, this function returns the amount that would actually be consumed by the system to satisfy it. This is needed for efficient user-defined memory management.
| ARCH_API bool ArchIsPtmallocActive | ( | ) |
Return true if ptmalloc is being used as the memory allocator.
ptmalloc3 is an external shared library providing implementations of the standard memory allocation functions (e.g. malloc, free). Consumers with special behavior that depends on this library may use this function to determine if it is the active allocator.
| ARCH_API bool ArchIsStlAllocatorOff | ( | ) |
Return true if the C++ STL allocator was requested to be turned off.
Under gcc, this is done by setting the environment variable GLIBCXX_FORCE_NEW, but it might differ (or not even be possible) for other platforms.
|
noexcept |
Prefetch the cache lines that [addr, addr+Size) occupy.
The template argument Align (which must be a power of two) states the alignment the caller guarantees for addr. This can avoid a runtime check for ranges that could straddle cache lines when geometrically impossible due to alignment. A zero Size prefetches nothing.
Use ArchPrefetchRange() if the length is not a compile-time constant.
Definition at line 193 of file prefetch.h.
|
noexcept |
Prefetch the cache lines that the count objects of type T starting at addr occupy, as in ArchPrefetchRange(vec.data(), vec.size()).
A zero count prefetches nothing.
Note the unit of the second argument follows the pointer, matching the usual C++ conventions: a void const * takes a byte count, as memcpy() does, and a typed pointer takes an object count, as std::copy_n() does.
count objects must actually fit in memory – count * sizeof(T) is not checked for overflow.
Definition at line 231 of file prefetch.h.
|
noexcept |
Prefetch the cache lines that [addr, addr+numBytes) occupy, where numBytes is a runtime value.
A zero numBytes prefetches nothing.
There is no alignment parameter: unlike ArchPrefetch(), this cannot fold the line count at compile time, so knowing the alignment of addr would not save it any work. Prefer ArchPrefetch() when the length is a constant – it unrolls to a straight run of prefetch instructions.
Definition at line 210 of file prefetch.h.
|
noexcept |
Prefetch for reading the object at addr with given locality.
The type T must be complete. Prefetches the number of cache lines that T occupies at addr.
Definition at line 243 of file prefetch.h.
|
noexcept |
Prefetch for writing the object at addr with given locality.
The type T must be complete. Prefetches the number of cache lines that T occupies at addr.
Definition at line 254 of file prefetch.h.