File indexing completed on 2025-08-27 09:30:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef FLATBUFFERS_DEFAULT_ALLOCATOR_H_
0018 #define FLATBUFFERS_DEFAULT_ALLOCATOR_H_
0019
0020 #include "flatbuffers/allocator.h"
0021 #include "flatbuffers/base.h"
0022
0023 namespace flatbuffers {
0024
0025
0026 class DefaultAllocator : public Allocator {
0027 public:
0028 uint8_t *allocate(size_t size) FLATBUFFERS_OVERRIDE {
0029 return new uint8_t[size];
0030 }
0031
0032 void deallocate(uint8_t *p, size_t) FLATBUFFERS_OVERRIDE { delete[] p; }
0033
0034 static void dealloc(void *p, size_t) { delete[] static_cast<uint8_t *>(p); }
0035 };
0036
0037
0038
0039
0040
0041 inline uint8_t *Allocate(Allocator *allocator, size_t size) {
0042 return allocator ? allocator->allocate(size)
0043 : DefaultAllocator().allocate(size);
0044 }
0045
0046 inline void Deallocate(Allocator *allocator, uint8_t *p, size_t size) {
0047 if (allocator)
0048 allocator->deallocate(p, size);
0049 else
0050 DefaultAllocator().deallocate(p, size);
0051 }
0052
0053 inline uint8_t *ReallocateDownward(Allocator *allocator, uint8_t *old_p,
0054 size_t old_size, size_t new_size,
0055 size_t in_use_back, size_t in_use_front) {
0056 return allocator ? allocator->reallocate_downward(old_p, old_size, new_size,
0057 in_use_back, in_use_front)
0058 : DefaultAllocator().reallocate_downward(
0059 old_p, old_size, new_size, in_use_back, in_use_front);
0060 }
0061
0062 }
0063
0064 #endif