ONE - On-device Neural Engine
Loading...
Searching...
No Matches
default_allocator.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef FLATBUFFERS_DEFAULT_ALLOCATOR_H_
18#define FLATBUFFERS_DEFAULT_ALLOCATOR_H_
19
21#include "flatbuffers/base.h"
22
23namespace flatbuffers {
24
25// DefaultAllocator uses new/delete to allocate memory regions
27 public:
28 uint8_t *allocate(size_t size) FLATBUFFERS_OVERRIDE {
29 return new uint8_t[size];
30 }
31
32 void deallocate(uint8_t *p, size_t) FLATBUFFERS_OVERRIDE { delete[] p; }
33
34 static void dealloc(void *p, size_t) { delete[] static_cast<uint8_t *>(p); }
35};
36
37// These functions allow for a null allocator to mean use the default allocator,
38// as used by DetachedBuffer and vector_downward below.
39// This is to avoid having a statically or dynamically allocated default
40// allocator, or having to move it between the classes that may own it.
41inline uint8_t *Allocate(Allocator *allocator, size_t size) {
42 return allocator ? allocator->allocate(size)
44}
45
46inline void Deallocate(Allocator *allocator, uint8_t *p, size_t size) {
47 if (allocator)
48 allocator->deallocate(p, size);
49 else
51}
52
53inline uint8_t *ReallocateDownward(Allocator *allocator, uint8_t *old_p,
54 size_t old_size, size_t new_size,
55 size_t in_use_back, size_t in_use_front) {
56 return allocator ? allocator->reallocate_downward(old_p, old_size, new_size,
57 in_use_back, in_use_front)
59 old_p, old_size, new_size, in_use_back, in_use_front);
60}
61
62} // namespace flatbuffers
63
64#endif // FLATBUFFERS_DEFAULT_ALLOCATOR_H_
virtual uint8_t * reallocate_downward(uint8_t *old_p, size_t old_size, size_t new_size, size_t in_use_back, size_t in_use_front)
Definition allocator.h:41
static void dealloc(void *p, size_t)
void deallocate(uint8_t *p, size_t) FLATBUFFERS_OVERRIDE
uint8_t * allocate(size_t size) FLATBUFFERS_OVERRIDE
uint8_t * ReallocateDownward(Allocator *allocator, uint8_t *old_p, size_t old_size, size_t new_size, size_t in_use_back, size_t in_use_front)
void Deallocate(Allocator *allocator, uint8_t *p, size_t size)
uint8_t * Allocate(Allocator *allocator, size_t size)
int32_t size[5]
Definition Slice.cpp:35
Configuration p
src_tensor allocator() -> init(p.src_info< NHWC >())