#pragma once /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ #include #include #include #include namespace Aws { namespace Crt { using Allocator = aws_allocator; extern AWS_CRT_CPP_API Allocator *g_allocator; template class StlAllocator : public std::allocator { public: using Base = std::allocator; StlAllocator() noexcept : Base() { m_allocator = g_allocator; } StlAllocator(Allocator *allocator) noexcept : Base() { m_allocator = allocator; } StlAllocator(const StlAllocator &a) noexcept : Base(a) { m_allocator = a.m_allocator; } template StlAllocator(const StlAllocator &a) noexcept : Base(a) { m_allocator = a.m_allocator; } ~StlAllocator() {} using size_type = std::size_t; template struct rebind { typedef StlAllocator other; }; using RawPointer = typename std::allocator_traits>::pointer; RawPointer allocate(size_type n, const void *hint = nullptr) { (void)hint; AWS_ASSERT(m_allocator); return static_cast(aws_mem_acquire(m_allocator, n * sizeof(T))); } void deallocate(RawPointer p, size_type) { AWS_ASSERT(m_allocator); aws_mem_release(m_allocator, p); } Allocator *m_allocator; }; } // namespace Crt } // namespace Aws