[#FOLLY_DECLARE_REUSED]
= FOLLY&lowbar;DECLARE&lowbar;REUSED
:mrdocs:

FOLLY&lowbar;DECLARE&lowbar;REUSED

== Synopsis

Declared in `&lt;folly&sol;SingletonThreadLocal&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
#define FOLLY&lowbar;DECLARE&lowbar;REUSED(name, ...)

----

== Description

Useful for local variables of container types, where it is desired to avoid the overhead associated with the local variable entering and leaving scope&period; Rather, where it is desired that the memory be reused between invocations of the same scope in the same thread rather than deallocated and reallocated between invocations of the same scope in the same thread&period; Note that the container will always be cleared between invocations&semi; it is only the backing memory allocation which is reused&period;

Example&colon;

void traverse&lowbar;perform(int root)&semi; template &lt;typename F&gt; void traverse&lowbar;each&lowbar;child&lowbar;r(int root, F const&amp;)&semi; void traverse&lowbar;depthwise(int root) &lcub; &sol;&sol; preserves some of the memory backing these per&hyphen;thread data structures FOLLY&lowbar;DECLARE&lowbar;REUSED(seen, std&colon;&colon;unordered&lowbar;set&lt;int&gt;)&semi; FOLLY&lowbar;DECLARE&lowbar;REUSED(work, std&colon;&colon;vector&lt;int&gt;)&semi; &sol;&sol; example algorithm that uses these per&hyphen;thread data structures work&period;push&lowbar;back(root)&semi; while (!work&period;empty()) &lcub; root &equals; work&period;back()&semi; work&period;pop&lowbar;back()&semi; seen&period;insert(root)&semi; traverse&lowbar;perform(root)&semi; traverse&lowbar;each&lowbar;child&lowbar;r(root, &lsqb;&amp;&rsqb;item) &lcub; if (!seen&period;count(item)) &lcub; work&period;push&lowbar;back(item)&semi; &rcub; &rcub;)&semi; &rcub; &rcub;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *name*
| The name of the local variable to declare&period;
| *&period;&period;&period;*
| The container type to reuse across invocations&period;
|===


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