Make ArenaOptions suitable for designated initializers.

PiperOrigin-RevId: 485433199
pull/10872/head
Chris Kennelly 2 years ago committed by Copybara-Service
parent 411cba1314
commit 15406e1d60
  1. 20
      src/google/protobuf/arena.h

@ -114,41 +114,33 @@ void arena_delete_object(void* object) {
struct ArenaOptions { struct ArenaOptions {
// This defines the size of the first block requested from the system malloc. // This defines the size of the first block requested from the system malloc.
// Subsequent block sizes will increase in a geometric series up to a maximum. // Subsequent block sizes will increase in a geometric series up to a maximum.
size_t start_block_size; size_t start_block_size = internal::AllocationPolicy::kDefaultStartBlockSize;
// This defines the maximum block size requested from system malloc (unless an // This defines the maximum block size requested from system malloc (unless an
// individual arena allocation request occurs with a size larger than this // individual arena allocation request occurs with a size larger than this
// maximum). Requested block sizes increase up to this value, then remain // maximum). Requested block sizes increase up to this value, then remain
// here. // here.
size_t max_block_size; size_t max_block_size = internal::GetDefaultArenaMaxBlockSize();
// An initial block of memory for the arena to use, or nullptr for none. If // An initial block of memory for the arena to use, or nullptr for none. If
// provided, the block must live at least as long as the arena itself. The // provided, the block must live at least as long as the arena itself. The
// creator of the Arena retains ownership of the block after the Arena is // creator of the Arena retains ownership of the block after the Arena is
// destroyed. // destroyed.
char* initial_block; char* initial_block = nullptr;
// The size of the initial block, if provided. // The size of the initial block, if provided.
size_t initial_block_size; size_t initial_block_size = 0;
// A function pointer to an alloc method that returns memory blocks of size // A function pointer to an alloc method that returns memory blocks of size
// requested. By default, it contains a ptr to the malloc function. // requested. By default, it contains a ptr to the malloc function.
// //
// NOTE: block_alloc and dealloc functions are expected to behave like // NOTE: block_alloc and dealloc functions are expected to behave like
// malloc and free, including Asan poisoning. // malloc and free, including Asan poisoning.
void* (*block_alloc)(size_t); void* (*block_alloc)(size_t) = nullptr;
// A function pointer to a dealloc method that takes ownership of the blocks // A function pointer to a dealloc method that takes ownership of the blocks
// from the arena. By default, it contains a ptr to a wrapper function that // from the arena. By default, it contains a ptr to a wrapper function that
// calls free. // calls free.
void (*block_dealloc)(void*, size_t); void (*block_dealloc)(void*, size_t) = nullptr;
ArenaOptions()
: start_block_size(internal::AllocationPolicy::kDefaultStartBlockSize),
max_block_size(internal::GetDefaultArenaMaxBlockSize()),
initial_block(nullptr),
initial_block_size(0),
block_alloc(nullptr),
block_dealloc(nullptr) {}
private: private:
internal::AllocationPolicy AllocationPolicy() const { internal::AllocationPolicy AllocationPolicy() const {

Loading…
Cancel
Save