MCPcopy Create free account
hub / github.com/arun11299/cpp-jwt / Arena

Class Arena

include/jwt/stack_alloc.hpp:46–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44 size_t alignment = alignof(std::max_align_t)
45>
46class Arena
47{
48public: // 'tors
49 Arena() noexcept
50 : ptr_(buf_)
51 {
52 static_assert (alignment <= alignof(std::max_align_t),
53 "Alignment chosen is more than the maximum supported alignment");
54 }
55
56 /// Non copyable and assignable
57 Arena(const Arena&) = delete;
58 Arena& operator=(const Arena&) = delete;
59
60 ~Arena()
61 {
62 ptr_ = nullptr;
63 }
64
65public: // Public APIs
66
67 /*
68 * Reserves space within the buffer of size atleast 'n'
69 * bytes.
70 * More bytes maybe reserved based on the alignment requirements.
71 *
72 * Returns:
73 * 1. The pointer within the storage buffer where the object can be constructed.
74 * 2. nullptr if space cannot be reserved for requested number of bytes
75 * (+ alignment padding if applicable)
76 */
77 template <
78 /// The requested alignment for this allocation.
79 /// Must be less than or equal to the 'alignment'.
80 size_t requested_alignment
81 >
82 char* allocate(size_t n) noexcept;
83
84 /*
85 * Free back the space pointed by p within the storage buffer.
86 */
87 void deallocate(char* p, size_t n) noexcept;
88
89 /*
90 * The size of the internal storage buffer.
91 */
92 constexpr static size_t size() noexcept
93 {
94 return N;
95 }
96
97 /*
98 * Returns number of remaining bytes within the storage buffer
99 * that can be used for further allocation requests.
100 */
101 size_t used() const noexcept
102 {
103 return static_cast<size_t>(ptr_ - buf_);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected