MCPcopy Create free account
hub / github.com/ElementsProject/elements / AllocateAligned

Method AllocateAligned

src/leveldb/util/arena.cc:38–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38char* Arena::AllocateAligned(size_t bytes) {
39 const int align = (sizeof(void*) > 8) ? sizeof(void*) : 8;
40 static_assert((align & (align - 1)) == 0,
41 "Pointer size should be a power of 2");
42 size_t current_mod = reinterpret_cast<uintptr_t>(alloc_ptr_) & (align - 1);
43 size_t slop = (current_mod == 0 ? 0 : align - current_mod);
44 size_t needed = bytes + slop;
45 char* result;
46 if (needed <= alloc_bytes_remaining_) {
47 result = alloc_ptr_ + slop;
48 alloc_ptr_ += needed;
49 alloc_bytes_remaining_ -= needed;
50 } else {
51 // AllocateFallback always returned aligned memory
52 result = AllocateFallback(bytes);
53 }
54 assert((reinterpret_cast<uintptr_t>(result) & (align - 1)) == 0);
55 return result;
56}
57
58char* Arena::AllocateNewBlock(size_t block_bytes) {
59 char* result = new char[block_bytes];

Callers 2

TESTFunction · 0.80
NewNodeMethod · 0.80

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.64