MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / allocate

Method allocate

include/chaiscript/dispatchkit/short_alloc.hpp:61–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59template <std::size_t N, std::size_t alignment>
60template <std::size_t ReqAlign>
61char*
62arena<N, alignment>::allocate(std::size_t n)
63{
64 static_assert(ReqAlign <= alignment, "alignment is too small for this arena");
65 assert(pointer_in_buffer(ptr_) && "short_alloc has outlived arena");
66 auto const aligned_n = align_up(n);
67 if (static_cast<decltype(aligned_n)>(buf_ + N - ptr_) >= aligned_n)
68 {
69 char* r = ptr_;
70 ptr_ += aligned_n;
71 return r;
72 }
73
74 static_assert(alignment <= alignof(std::max_align_t), "you've chosen an "
75 "alignment that is larger than alignof(std::max_align_t), and "
76 "cannot be guaranteed by normal operator new");
77 return static_cast<char*>(::operator new(n));
78}
79
80template <std::size_t N, std::size_t alignment>
81void

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected