Pigweed
 
Loading...
Searching...
No Matches
pw::multibuf::SimpleAllocator Class Reference

A simple first-fit MultiBufAllocator. More...

#include <simple_allocator.h>

Inheritance diagram for pw::multibuf::SimpleAllocator:
pw::multibuf::MultiBufAllocator pw::multibuf::test::SimpleAllocatorForTest< kDataSizeBytes, kMetaSizeBytes >

Public Member Functions

 SimpleAllocator (ByteSpan data_area, pw::allocator::Allocator &metadata_alloc, size_t alignment=1)
 
- Public Member Functions inherited from pw::multibuf::MultiBufAllocator
 MultiBufAllocator (MultiBufAllocator &)=delete
 `MultiBufAllocator is not copyable or movable.
 
MultiBufAllocatoroperator= (MultiBufAllocator &)=delete
 
 MultiBufAllocator (MultiBufAllocator &&)=delete
 
MultiBufAllocatoroperator= (MultiBufAllocator &&)=delete
 
std::optional< MultiBufAllocate (size_t size)
 
std::optional< MultiBufAllocate (size_t min_size, size_t desired_size)
 
std::optional< MultiBufAllocateContiguous (size_t size)
 
std::optional< MultiBufAllocateContiguous (size_t min_size, size_t desired_size)
 
std::optional< size_t > GetBackingCapacity ()
 

Private Member Functions

pw::Result< MultiBufDoAllocate (size_t min_size, size_t desired_size, ContiguityRequirement contiguity_requirement) final
 
std::optional< size_t > DoGetBackingCapacity () final
 

Friends

class internal::LinkedRegionTracker
 

Additional Inherited Members

- Protected Member Functions inherited from pw::multibuf::MultiBufAllocator
void MoreMemoryAvailable (size_t size_available, size_t contiguous_size_available)
 

Detailed Description

A simple first-fit MultiBufAllocator.

Constructor & Destructor Documentation

◆ SimpleAllocator()

pw::multibuf::SimpleAllocator::SimpleAllocator ( ByteSpan  data_area,
pw::allocator::Allocator metadata_alloc,
size_t  alignment = 1 
)

Creates a new SimpleAllocator.

Parameters
[in]data_areaThe region to use for storing chunk memory.
[in]metadata_allocThe allocator to use for metadata tracking the in-use regions. This allocator must be thread-safe if the resulting buffers may travel to another thread. SynchronizedAllocator can be used to create a thread-safe allocator from a non-thread-safe allocator.
[in]alignmentThe alignment to use. All chunks allocated by this allocator will start aligned with the specified alignment. The alignment can change if the prefix Chunk methods are used. The supplied data_area must be aligned (both start and end) to the specified alignment. Defaults to 1.

Member Function Documentation

◆ DoAllocate()

pw::Result< MultiBuf > pw::multibuf::SimpleAllocator::DoAllocate ( size_t  min_size,
size_t  desired_size,
ContiguityRequirement  contiguity_requirement 
)
finalprivatevirtual

Attempts to allocate a MultiBuf of at least min_size bytes and at most desired_size bytes.

Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: Returns the buffer if the allocation was successful.
* 
*     RESOURCE_EXHAUSTED: Insufficient memory is available currently.
* 
*     OUT_OF_RANGE: This amount of memory will not become possible to
*     allocate in the future, or this allocator is unable to signal via
*     ``MoreMemoryAvailable`` (this will result in asynchronous allocations
*     failing immediately on OOM).
* 
*  

Implements pw::multibuf::MultiBufAllocator.

◆ DoGetBackingCapacity()

std::optional< size_t > pw::multibuf::SimpleAllocator::DoGetBackingCapacity ( )
inlinefinalprivatevirtual

Returns the total amount of memory provided by this object.

This is an optional method. Some memory providers may not have an easily defined capacity, e.g. the system allocator.

Return values
thetotal memory if known.
``nullopt_t``if the total memory is not knowable.

Implements pw::multibuf::MultiBufAllocator.


The documentation for this class was generated from the following file: