]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/util/memory_allocator.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
9 #include "rocksdb/memory_allocator.h"
13 struct CustomDeleter
{
14 CustomDeleter(MemoryAllocator
* a
= nullptr) : allocator(a
) {}
16 void operator()(char* ptr
) const {
18 allocator
->Deallocate(reinterpret_cast<void*>(ptr
));
24 MemoryAllocator
* allocator
;
27 using CacheAllocationPtr
= std::unique_ptr
<char[], CustomDeleter
>;
29 inline CacheAllocationPtr
AllocateBlock(size_t size
,
30 MemoryAllocator
* allocator
) {
32 auto block
= reinterpret_cast<char*>(allocator
->Allocate(size
));
33 return CacheAllocationPtr(block
, allocator
);
35 return CacheAllocationPtr(new char[size
]);
38 } // namespace rocksdb