From 1a7a7fca804afa1cf67f8be5e71092898ba40334 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 18 Oct 2017 12:22:18 -0700 Subject: Merge from google internal --- src/google/protobuf/arena.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/google/protobuf/arena.h') 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 @@ -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 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 friend class Map; -- cgit v1.2.3