Simd Library Documentation.

Home | Release Notes | Download | Documentation | Issues | GitHub
Allocator< T > Struct Template Reference

Aligned memory allocator for Simd C++ types and STL containers. More...

#include <SimdAllocator.hpp>

Static Public Member Functions

static SIMD_INLINE void * Allocate (size_t size, size_t align)
 Allocates an aligned memory block. More...
 
static SIMD_INLINE void Free (void *ptr)
 Frees an aligned memory block. More...
 
static SIMD_INLINE size_t Align (size_t size, size_t align)
 Rounds a size up to the requested alignment. More...
 
static SIMD_INLINE void * Align (void *ptr, size_t align)
 Rounds a pointer up to the requested alignment. More...
 
static SIMD_INLINE size_t Alignment ()
 Returns the preferred memory alignment for optimized Simd code. More...
 

Detailed Description

template<class T>
struct Simd::Allocator< T >

Aligned memory allocator for Simd C++ types and STL containers.

The allocator is a stateless wrapper over Simd aligned memory functions. It is used by Simd C++ types such as View, Frame, Pyramid, Detection, ImageMatcher and ShiftDetector to allocate image data, temporary buffers and other owned storage with the alignment required by optimized SIMD code.

It also implements the standard allocator interface, so containers such as std::vector<T, Simd::Allocator<T> > can keep their elements in aligned memory. All instances of this allocator are interchangeable because they do not own allocator state.

Member Function Documentation

◆ Allocate()

void * Allocate ( size_t  size,
size_t  align 
)
static

Allocates an aligned memory block.

Allocates a contiguous block of at least size bytes whose start address is a multiple of align. This function is used directly by Simd C++ classes when they allocate owned buffers. The STL allocator method allocate() calls it with size * sizeof(T) bytes and the default value returned by Alignment().

Note
The memory allocated by this function must be released by Free(). Do not release it with free or delete.
Parameters
[in]size- the number of bytes to allocate.
[in]align- the required alignment in bytes. It must be a power of two. Use Alignment() to obtain the preferred alignment for the current platform.
Returns
a pointer to the allocated memory block, or NULL if allocation fails.

◆ Free()

void Free ( void *  ptr)
static

Frees an aligned memory block.

Releases a memory block returned by Allocate(). Simd C++ classes call this function when they destroy or recreate owned buffers, and the STL allocator method deallocate() delegates to it.

Parameters
[in]ptr- a pointer to the memory block to free. Passing NULL is safe.

◆ Align() [1/2]

size_t Align ( size_t  size,
size_t  align 
)
static

Rounds a size up to the requested alignment.

Returns the smallest value that is both greater than or equal to size and a multiple of align. Simd::View uses this helper to compute aligned image strides from row byte sizes.

Parameters
[in]size- the original size in bytes or elements.
[in]align- the required alignment in bytes. It must be a positive power of two.
Returns
the aligned size.

◆ Align() [2/2]

void * Align ( void *  ptr,
size_t  align 
)
static

Rounds a pointer up to the requested alignment.

Returns the first address at or after ptr that is a multiple of align. Simd::View uses this helper when it is created over an external buffer and must align the stored data pointer to the requested boundary. The function does not allocate memory and does not change ownership of the buffer.

Parameters
[in]ptr- the original pointer.
[in]align- the required alignment in bytes. It must be a positive power of two.
Returns
the aligned address.

◆ Alignment()

size_t Alignment ( )
static

Returns the preferred memory alignment for optimized Simd code.

The value reflects the active SIMD implementation on the current platform and is used as the default alignment for Simd C++ owned buffers and STL container allocations made through this allocator.

Returns
the preferred memory alignment in bytes.