Skip to content

Memory allocation

aligned_allocate function

template <typename T = void, size_t alignment = 64>
T *aligned_allocate(size_t size = 1)

Allocates aligned memory

Source code
template <typename T = void, size_t alignment = 64>
CMT_INTRINSIC T* aligned_allocate(size_t size = 1)
{
    T* ptr = static_cast<T*>(CMT_ASSUME_ALIGNED(
        details::aligned_malloc(std::max(alignment, size * details::elementsize<T>()), alignment),
        alignment));
    return ptr;
}

https://github.com/kfrlib/kfr/blob//include/kfr/cometa/memory.hpp#L129

template <typename T = void>
T *aligned_allocate(size_t size, size_t alignment)

Allocates aligned memory

Source code
template <typename T = void>
CMT_INTRINSIC T* aligned_allocate(size_t size, size_t alignment)
{
    T* ptr = static_cast<T*>(CMT_ASSUME_ALIGNED(
        details::aligned_malloc(std::max(alignment, size * details::elementsize<T>()), alignment),
        alignment));
    return ptr;
}

https://github.com/kfrlib/kfr/blob//include/kfr/cometa/memory.hpp#L138

aligned_deallocate function

template <typename T = void> void aligned_deallocate(T *ptr)

Deallocates aligned memory

Source code
template <typename T = void>
CMT_INTRINSIC void aligned_deallocate(T* ptr)
{
    return details::aligned_free(ptr);
}

https://github.com/kfrlib/kfr/blob//include/kfr/cometa/memory.hpp#L148

data_allocator

data_allocator class

template <typename T> data_allocator

Aligned allocator

Source code
template <typename T>
struct data_allocator
{
    using value_type      = T;
    using pointer         = T*;
    using const_pointer   = const T*;
    using reference       = T&;
    using const_reference = const T&;
    using size_type       = std::size_t;
    using difference_type = std::ptrdiff_t;

    template <typename U>
    struct rebind
    {
        using other = data_allocator<U>;
    };
    constexpr data_allocator() CMT_NOEXCEPT                      = default;
    constexpr data_allocator(const data_allocator&) CMT_NOEXCEPT = default;
    template <typename U>
    constexpr data_allocator(const data_allocator<U>&) CMT_NOEXCEPT
    {
    }
    pointer allocate(size_type n) const
    {
        pointer result = aligned_allocate<value_type>(n);
        if (!result)
            CMT_THROW(std::bad_alloc());
        return result;
    }
    void deallocate(pointer p, size_type) { aligned_deallocate(p); }
}

https://github.com/kfrlib/kfr/blob//include/kfr/cometa/memory.hpp#L197


Auto-generated from sources, Revision , https://github.com/kfrlib/kfr/blob//include/kfr/