[#FOLLY_DECLARE_REUSED] = FOLLY_DECLARE_REUSED :mrdocs: FOLLY_DECLARE_REUSED == Synopsis Declared in `<folly/SingletonThreadLocal.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- #define FOLLY_DECLARE_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. 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. Note that the container will always be cleared between invocations; it is only the backing memory allocation which is reused. Example: void traverse_perform(int root); template <typename F> void traverse_each_child_r(int root, F const&); void traverse_depthwise(int root) { // preserves some of the memory backing these per‐thread data structures FOLLY_DECLARE_REUSED(seen, std::unordered_set<int>); FOLLY_DECLARE_REUSED(work, std::vector<int>); // example algorithm that uses these per‐thread data structures work.push_back(root); while (!work.empty()) { root = work.back(); work.pop_back(); seen.insert(root); traverse_perform(root); traverse_each_child_r(root, [&]item) { if (!seen.count(item)) { work.push_back(item); } }); } } == Parameters [cols="1,4"] |=== | Name| Description | *name* | The name of the local variable to declare. | *...* | The container type to reuse across invocations. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#