diff options
Diffstat (limited to 'src/google/protobuf/arena.h')
-rw-r--r-- | src/google/protobuf/arena.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index a0cee22b..32be9a17 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -61,7 +61,7 @@ class Arena; // defined below class Message; // message.h namespace internal { -class ArenaString; // arenastring.h +struct ArenaStringPtr; // arenastring.h class LazyField; // lazy_field.h template<typename Type> @@ -223,6 +223,14 @@ class LIBPROTOBUF_EXPORT Arena { Init(options); } + // Block overhead. Use this as a guide for how much to over-allocate the + // initial block if you want an allocation of size N to fit inside it. + // + // WARNING: if you allocate multiple objects, it is difficult to guarantee + // that a series of allocations will fit in the initial block, especially if + // Arena changes its alignment guarantees in the future! + static const size_t kBlockOverhead = internal::ArenaImpl::kHeaderSize; + // Default constructor with sensible default options, tuned for average // use-cases. Arena() : impl_(ArenaOptions()) { Init(ArenaOptions()); } @@ -524,10 +532,9 @@ class LIBPROTOBUF_EXPORT Arena { // returns the total space used by the arena which is the sums of the sizes // of the allocated blocks. This method is not thread-safe. GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE uint64 Reset() { - uint64 space_allocated = SpaceAllocated(); // Call the reset hook if (on_arena_reset_ != NULL) { - on_arena_reset_(this, hooks_cookie_, space_allocated); + on_arena_reset_(this, hooks_cookie_, impl_.SpaceAllocated()); } return impl_.Reset(); } @@ -912,7 +919,7 @@ class LIBPROTOBUF_EXPORT Arena { template <typename Type> friend class ::google::protobuf::internal::GenericTypeHandler; - friend class internal::ArenaString; // For AllocateAligned. + friend struct internal::ArenaStringPtr; // For AllocateAligned. friend class internal::LazyField; // For CreateMaybeMessage. template <typename Key, typename T> friend class Map; |