Skip to content

Memory allocation

aligned_allocate function

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

Allocates aligned memory

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

https://github.com/kfrlib/kfr/blob//include/kfr/base/memory.hpp#L117

aligned_deallocate function

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

Deallocates aligned memory

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

https://github.com/kfrlib/kfr/blob//include/kfr/base/memory.hpp#L127

allocator

allocator class

template <typename T> allocator

Aligned allocator

Source code
template <typename T>
struct 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 = allocator<U>;
    };
    constexpr allocator() CMT_NOEXCEPT                 = default;
    constexpr allocator(const allocator&) CMT_NOEXCEPT = default;
    template <typename U>
    constexpr allocator(const allocator<U>&) CMT_NOEXCEPT
    {
    }
    pointer address(reference x) const CMT_NOEXCEPT { return std::addressof(x); }
    const_pointer address(const_reference x) const CMT_NOEXCEPT { return std::addressof(x); }
    pointer allocate(size_type n, std::allocator<void>::const_pointer = 0) 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); }
    size_type max_size() const { return std::numeric_limits<size_type>::max() / sizeof(value_type); }
    template <typename U, typename... Args>
    void construct(U* p, Args&&... args)
    {
        ::new (pvoid(p)) U(std::forward<Args>(args)...);
    }
    template <typename U>
    void destroy(U* p)
    {
        p->~U();
    }
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/memory.hpp#L176


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