1 /* 2 * 3 * Copyright 2017 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 // \file Arena based allocator 20 // Allows very fast allocation of memory, but that memory cannot be freed until 21 // the arena as a whole is freed 22 // Tracks the total memory allocated against it, so that future arenas can 23 // pre-allocate the right amount of memory 24 25 #ifndef GRPC_CORE_LIB_GPR_ARENA_H 26 #define GRPC_CORE_LIB_GPR_ARENA_H 27 28 #include <grpc/support/port_platform.h> 29 30 #include <stddef.h> 31 32 typedef struct gpr_arena gpr_arena; 33 34 // Create an arena, with \a initial_size bytes in the first allocated buffer 35 gpr_arena* gpr_arena_create(size_t initial_size); 36 // Allocate \a size bytes from the arena 37 void* gpr_arena_alloc(gpr_arena* arena, size_t size); 38 // Destroy an arena, returning the total number of bytes allocated 39 size_t gpr_arena_destroy(gpr_arena* arena); 40 41 #endif /* GRPC_CORE_LIB_GPR_ARENA_H */ 42