Sha256: 498200cc5405de6c55eb4b7daa2821461b447eab4a4e3fab709765ea3f488cbc

Contents?: true

Size: 1.48 KB

Versions: 13

Compression:

Stored size: 1.48 KB

Contents

// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC.  All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

#ifndef UPB_MEM_ARENA_HPP_
#define UPB_MEM_ARENA_HPP_

#ifdef __cplusplus

#include <memory>

#include "upb/mem/arena.h"

namespace upb {

class Arena {
 public:
  // A simple arena with no initial memory block and the default allocator.
  Arena() : ptr_(upb_Arena_New(), upb_Arena_Free) {}
  Arena(char* initial_block, size_t size)
      : ptr_(upb_Arena_Init(initial_block, size, &upb_alloc_global),
             upb_Arena_Free) {}

  upb_Arena* ptr() const { return ptr_.get(); }

  void Fuse(Arena& other) { upb_Arena_Fuse(ptr(), other.ptr()); }

 protected:
  std::unique_ptr<upb_Arena, decltype(&upb_Arena_Free)> ptr_;
};

// InlinedArena seeds the arenas with a predefined amount of memory. No heap
// memory will be allocated until the initial block is exceeded.
template <int N>
class InlinedArena : public Arena {
 public:
  InlinedArena() : Arena(initial_block_, N) {}
  ~InlinedArena() {
    // Explicitly destroy the arena now so that it does not outlive
    // initial_block_.
    ptr_.reset();
  }

 private:
  InlinedArena(const InlinedArena&) = delete;
  InlinedArena& operator=(const InlinedArena&) = delete;

  char initial_block_[N];
};

}  // namespace upb

#endif  // __cplusplus

#endif  // UPB_MEM_ARENA_HPP_

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
grpc-1.67.0 third_party/upb/upb/mem/arena.hpp
grpc-1.67.0.pre1 third_party/upb/upb/mem/arena.hpp
grpc-1.66.0 third_party/upb/upb/mem/arena.hpp
grpc-1.66.0.pre5 third_party/upb/upb/mem/arena.hpp
grpc-1.66.0.pre3 third_party/upb/upb/mem/arena.hpp
grpc-1.63.2 third_party/upb/upb/mem/arena.hpp
grpc-1.64.3 third_party/upb/upb/mem/arena.hpp
grpc-1.65.2 third_party/upb/upb/mem/arena.hpp
grpc-1.65.1 third_party/upb/upb/mem/arena.hpp
grpc-1.65.0 third_party/upb/upb/mem/arena.hpp
grpc-1.65.0.pre2 third_party/upb/upb/mem/arena.hpp
grpc-1.65.0.pre1 third_party/upb/upb/mem/arena.hpp
grpc-1.63.0 third_party/upb/upb/mem/arena.hpp