boost_sqlite 1
A sqlite C++ library
Loading...
Searching...
No Matches
allocator.hpp
1//
2// Copyright (c) 2022 Klemens Morgenstern (klemens.morgenstern@gmx.net)
3//
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7
8#ifndef BOOST_SQLITE_ALLOCATOR_HPP
9#define BOOST_SQLITE_ALLOCATOR_HPP
10
11#include <boost/sqlite/detail/config.hpp>
12
13#include <cstddef>
14#include <cstdint>
15
16BOOST_SQLITE_BEGIN_NAMESPACE
17
18template<typename T>
19struct allocator
20{
21 constexpr allocator() noexcept {}
22 constexpr allocator( const allocator& other ) noexcept {}
23 template< class U >
24 constexpr allocator( const allocator<U>& other ) noexcept {}
25
26#if defined(SQLITE_4_BYTE_ALIGNED_MALLOC)
27 constexpr static std::size_t alignment = 4u;
28#else
29 constexpr static std::size_t alignment = 8u;
30#endif
31
32 static_assert(alignof(T) <= alignment, "T alignment can't be fulfilled by sqlite");
33 [[nodiscard]] T* allocate( std::size_t n )
34 {
35 return static_cast<T*>(sqlite3_malloc64(n * sizeof(T)));
36 }
37 void deallocate( T* p, std::size_t)
38 {
39 return sqlite3_free(p);
40 }
41};
42
43BOOST_SQLITE_END_NAMESPACE
44
45#endif //BOOST_SQLITE_ALLOCATOR_HPP