class AnyBufferAllocator
Defined at line 148 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/message_storage.h
|AnyBufferAllocator| is a type-erasing buffer allocator. Its main purpose is
to extend the caller-allocating call/reply flavors to work with a flexible
range of buffer-like types ("memory resources").
This class is similar in spirit to a |std::pmr::polymorphic_allocator|,
except that it is specialized to allocating buffers (ranges of bytes).
This class is compact (4 machine words), such that it may be efficiently
moved around as a temporary value.
If initialized with a |BufferSpan|, allocates in that buffer span. If
initialized with a reference to some arena, allocates in that arena.
To extend |AnyBufferAllocator| to work with future buffer-like types,
declare this function for a user type |R| in the same namespace as the
user type:
fidl::AnyMemoryResource MakeFidlAnyMemoryResource(R memory_resource);
If possible, it is recommended to only declare this function as a friend of
the user type (i.e. declare it within the user type definition, the "hidden
member friend pattern"), such that it is hidden from qualified calls and only
findable by ADL.
Public Methods
fit::result<fidl::Error, fidl::BufferSpan> TryAllocate (uint32_t num_bytes)
Attempt to allocate |size| bytes from the allocator, returning a view when
successful and an error otherwise.
Defined at line 43 of file ../../sdk/lib/fidl/cpp/wire/message_storage.cc
uint8_t * Allocate (uint32_t num_bytes)
Allocates a buffer of size |num_bytes|.
If the underlying memory resource cannot satisfy the allocation, it should
return nullptr, and preserve its original state before the allocation.
Defined at line 154 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/message_storage.h
Friends
template <typename MemoryResource>
AnyBufferAllocator AnyBufferAllocator (MemoryResource && resource)