[#absl-Cord-GetAppendBuffer]
= xref:absl.adoc[absl]::xref:absl/Cord.adoc[Cord]::GetAppendBuffer
:relfileprefix: ../../
:mrdocs:

Returns a CordBuffer, re&hyphen;using potential existing capacity in this cord&period;

== Synopsis

Declared in `&lt;absl&sol;strings&sol;cord&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:absl/CordBuffer.adoc[CordBuffer]
GetAppendBuffer(
    size&lowbar;t capacity,
    size&lowbar;t min&lowbar;capacity = 16);
----

== Description

Cord instances may have additional unused capacity in the last (or first) nodes of the underlying tree to facilitate amortized growth&period; This method allows applications to explicitly use this spare capacity if available, or create a new CordBuffer instance otherwise&period; If this cord has a final non&hyphen;shared node with at least `min&lowbar;capacity` available, then this method will return that buffer including its data contents&period; I&period;e&period;&semi; the returned buffer will have a non&hyphen;zero length, and a capacity of at least `buffer&period;length &plus; min&lowbar;capacity`&period; Otherwise, this method will return `CordBuffer&colon;&colon;CreateWithDefaultLimit(capacity)`&period;

Below an example of using GetAppendBuffer&period; Notice that in this example we use `GetAppendBuffer()` only on the first iteration&period; As we know nothing about any initial extra capacity in `cord`, we may be able to use the extra capacity&period; But as we add new buffers with fully utilized contents after that we avoid calling `GetAppendBuffer()` on subsequent iterations&colon; while this works fine, it results in an unnecessary inspection of cord contents&colon;

void AppendRandomDataToCord(absl&colon;&colon;Cord &amp;cord, size&lowbar;t n) &lcub; bool first &equals; true&semi; while (n &gt; 0) &lcub; CordBuffer buffer &equals; first ? cord&period;GetAppendBuffer(n) &colon; CordBuffer&colon;&colon;CreateWithDefaultLimit(n)&semi; absl&colon;&colon;Span&lt;char&gt; data &equals; buffer&period;available&lowbar;up&lowbar;to(n)&semi; FillRandomValues(data&period;data(), data&period;size())&semi; buffer&period;IncreaseLengthBy(data&period;size())&semi; cord&period;Append(std&colon;&colon;move(buffer))&semi; n &hyphen;&equals; data&period;size()&semi; first &equals; false&semi; &rcub; &rcub;

== Return Value

A CordBuffer reusing spare capacity when available&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *capacity*
| The desired capacity of the returned buffer&period;
| *min&lowbar;capacity*
| The minimum extra capacity required to reuse existing spare capacity&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
