[#BloombergLP-bslstl-Function_SmallObjectOptimization] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslstl.adoc[bslstl]::Function_SmallObjectOptimization :relfileprefix: ../../ :mrdocs: This utility `struct` provides a namespace for several types, type traits, and constants used in the implementation of the small‐object optimization for `bsl::function`. == Synopsis Declared in `<bslstl_function_smallobjectoptimization.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class Function_SmallObjectOptimization; ---- == Types [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslstl/Function_SmallObjectOptimization/InplaceBuffer.adoc[`InplaceBuffer`] | This `union` defines the storage area for a functor representation. The design uses the small‐object optimization in an attempt to avoid allocations for objects that are no larger than `InplaceBuffer`. When the target object is no larger than `InplaceBuffer`, the small‐object optimization can be used by storing the target directly within the `InplaceBuffer`. | xref:BloombergLP/bslstl/Function_SmallObjectOptimization/IsInplaceFunc.adoc[`IsInplaceFunc`] | This class is a Boolean metafunction that determines whether or not the specified `FN` template parameter should be allocated within the footprint of the `InplaceBuffer` (i.e., using the small‐object optimization.) | xref:BloombergLP/bslstl/Function_SmallObjectOptimization/SooFuncSize.adoc[`SooFuncSize`] | This class template provides a metafunction that `bsl::function` uses to determine the size of an object, and whether to store it using the small‐object optimization (SOO) or not. The `value` member of this class encodes the size of the specified `TP` type as follows: |=== == Static Data Members [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslstl/Function_SmallObjectOptimization/k_NON_SOO_SMALL_SIZE.adoc[`k_NON_SOO_SMALL_SIZE`] | `SooFuncSize` (below) adds this value to the size of a small stateful functor to indicate that, despite being small, it should not be allocated inplace using the small object optimization (SOO), i.e., because it does not have a nothrow move constructor and cannot, therefore, be swapped safely. When a size larger than this constant is seen, the actual object size can be determined by subtracting this constant. A useful quality of this encoding is that if `SZ <= sizeof(InplaceBuffer)` for some object size `SZ`, then `SZ + k_NON_SOO_SMALL_SIZE > sizeof(InplaceBuffer)`, thus `SooFuncSize` (below) for any object that should not be allocated inplace is larger than `sizeof(InplaceBuffer)`, and the `SooFuncSize` for any object that _should_ be allocated inplace is smaller than or equal to `sizeof(InplaceBuffer)`, making the test for "is inplace function" simple. Note that it is assumed that no actual object has a size larger than this constant. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#