Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Alibaba MNN Protobuf ArenaString H

From Leeroopedia


Knowledge Sources
Domains Serialization, Memory_Management
Last Updated 2026-02-10 12:00 GMT

Overview

Header implementing arena-aware string storage for Protocol Buffers string fields, avoiding redundant heap allocations.

Description

This header defines the ArenaStringPtr class, which manages string field storage within protobuf messages in a way that is compatible with arena allocation. When a message is arena-allocated, its string fields use the arena's memory pool rather than separate heap allocations, reducing fragmentation and improving cache locality. MNN vendors this header because string fields are pervasive in TensorFlow and Caffe model protobuf definitions (node names, op types, tensor names), making arena-aware string handling essential for parsing performance.

Usage

Vendored dependency used internally by MNN for parsing protobuf-based model formats (TensorFlow, Caffe). Not directly imported by end users.

Code Reference

Source Location

  • Repository: Alibaba_MNN
  • File: 3rd_party/protobuf/src/google/protobuf/arenastring.h
  • Lines: 1-420

Signature

namespace google {
namespace protobuf {
namespace internal {
class PROTOBUF_EXPORT ArenaStringPtr {
  const std::string& Get() const;
  std::string* Mutable(Arena* arena);
  void Set(const std::string& value, Arena* arena);
  void Destroy(Arena* arena);
};
}  // namespace internal
}  // namespace protobuf
}  // namespace google

Import

#include "3rd_party/protobuf/src/google/protobuf/arenastring.h"

I/O Contract

Inputs

Name Type Required Description
arena Arena* No Arena pointer for arena-based allocation; nullptr for heap allocation
value const std::string& Yes String value to store in the arena-managed field

Outputs

Name Type Description
string reference const std::string& Read access to the stored string value
mutable pointer std::string* Mutable pointer for in-place string modification

Usage Examples

// MNN internal usage (within generated protobuf code)
internal::ArenaStringPtr name_;
name_.Set("conv2d_1", arena);
const std::string& n = name_.Get();
std::string* mutable_n = name_.Mutable(arena);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment