google protocol-buffers c++ repeated 链表结构释放内存空间

在使用 Repeated 类型 链表结构 使用add_foo() 以后,要注意clear_foo() 释放内存空间,最好的办法是在该链表类的析构方法中执行 this->clear_foo();

Repeated Embedded Message Fields

Given the message type:

message Bar {}

For this field definitions:

repeated Bar foo = 1;

The compiler will generate the following accessor methods:

  • int foo_size() const: Returns the number of elements currently in the field.
  • const Bar& foo(int index) const: Returns the element at the given zero-based index.
  • Bar* mutable_foo(int index): Returns a mutable pointer to the Bar object that stores the value of the element at the given zero-based index. The pointer is invalidated by a call to Clear() or clear_foo(), or by manipulating the underlying RepeatedPtrField in a way that would remove this element.
  • Bar* add_foo(): Adds a new element and returns a pointer to it. The returned Bar will have none of its fields set (i.e. it will be identical to a newly-allocated Bar). The pointer is invalidated by a call to Clear() or clear_foo(), or by manipulating the underlying RepeatedPtrField in a way that would remove this element.
  • void clear_foo(): Removes all elements from the field. After calling this, foo_size() will return zero.
  • const RepeatedPtrField<Bar>& foo() const: Returns the underlying RepeatedPtrField that stores the field's elements. This container class provides STL-like iterators and other methods.
  • RepeatedPtrField<Bar>* mutable_foo(): Returns a mutable pointer to the underlying RepeatedPtrField that stores the field's elements. This container class provides STL-like iterators and other methods.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值