Allocator designed to allocate a single chunk at any given time.
This restriction allows the allocator to manage its chunk metadata directly, without relying on the metadata allocator.
Public Member Functions | |
| SingleChunkAllocator (Allocator &metadata_allocator) | |
| void | SetRegion (ByteSpan region) |
Public Member Functions inherited from pw::multibuf::v1_adapter::internal::ChunkAllocator | |
| constexpr Allocator & | metadata_allocator () const |
| constexpr size_t | alignment () const |
| constexpr size_t | available () const |
| constexpr ByteSpan | buffer () const |
| std::optional< OwnedChunk > | AllocateChunk (size_t min_size, size_t desired_size) |
| std::optional< OwnedChunk > | AllocateChunk (size_t size) |
Public Member Functions inherited from pw::Allocator | |
| void * | Allocate (Layout layout) |
| template<typename T , int &... kExplicitGuard, std::enable_if_t<!std::is_array_v< T >, int > = 0, typename... Args> | |
| T * | New (Args &&... args) |
| template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>, std::enable_if_t< is_bounded_array_v< T >, int > = 0> | |
| ElementType * | New () |
| template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>, std::enable_if_t< is_unbounded_array_v< T >, int > = 0> | |
| ElementType * | New (size_t count) |
| template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>, std::enable_if_t< is_unbounded_array_v< T >, int > = 0> | |
| ElementType * | New (size_t count, size_t alignment) |
Constructs an alignment-byte aligned array of count objects. | |
| template<typename T , int &... kExplicitGuard, std::enable_if_t<!std::is_array_v< T >, int > = 0, typename... Args> | |
| UniquePtr< T > | MakeUnique (Args &&... args) |
| template<typename T , std::enable_if_t< is_unbounded_array_v< T >, int > = 0> | |
| UniquePtr< T > | MakeUnique (size_t size) |
| template<typename T , std::enable_if_t< is_unbounded_array_v< T >, int > = 0> | |
| UniquePtr< T > | MakeUnique (size_t size, size_t alignment) |
| template<typename T , std::enable_if_t< is_bounded_array_v< T >, int > = 0> | |
| UniquePtr< T > | MakeUnique () |
| template<typename T , int &... kExplicitGuard, std::enable_if_t<!std::is_array_v< T >, int > = 0, typename... Args> | |
| SharedPtr< T > | MakeShared (Args &&... args) |
| template<typename T , std::enable_if_t< is_unbounded_array_v< T >, int > = 0> | |
| SharedPtr< T > | MakeShared (size_t size) |
| template<typename T , std::enable_if_t< is_unbounded_array_v< T >, int > = 0> | |
| SharedPtr< T > | MakeShared (size_t size, size_t alignment) |
| template<typename T , std::enable_if_t< is_bounded_array_v< T >, int > = 0> | |
| SharedPtr< T > | MakeShared () |
| bool | Resize (void *ptr, size_t new_size) |
| void * | Reallocate (void *ptr, Layout new_layout) |
| size_t | GetAllocated () const |
| std::optional< Fragmentation > | MeasureFragmentation () const |
| Returns fragmentation information for the allocator's memory region. | |
Public Member Functions inherited from pw::Deallocator | |
| constexpr const Capabilities & | capabilities () const |
| constexpr bool | HasCapability (Capability capability) const |
| Returns whether a given capability is enabled for this object. | |
| void | Deallocate (void *ptr) |
| template<typename ElementType > | |
| void | DeleteArray (ElementType *ptr, size_t count) |
| StatusWithSize | GetCapacity () const |
| bool | IsEqual (const Deallocator &other) const |
| template<typename T , int &... kExplicitGuard, std::enable_if_t<!std::is_array_v< T >, int > = 0> | |
| void | Delete (T *ptr) |
| template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>, std::enable_if_t< is_bounded_array_v< T >, int > = 0> | |
| void | Delete (ElementType *ptr) |
| template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>, std::enable_if_t< is_unbounded_array_v< T >, int > = 0> | |
| void | Delete (ElementType *ptr, size_t count) |
Protected Member Functions | |
| constexpr bool | control_block_free () const |
| void | DeallocateControlBlock (void *ptr) |
| Release the chunk shared pointer metadata. | |
| void * | DoAllocate (Layout layout) override |
| void | DoDeallocate (void *ptr) override |
| Region * | AllocateRegion (size_t min_size, size_t desired_size) override |
| size_t | TryDeallocateRegion (void *ptr) override |
| virtual void | Destroy () |
Protected Member Functions inherited from pw::multibuf::v1_adapter::internal::ChunkAllocator | |
| PW_PACKED (struct) Region | |
| ChunkAllocator (Allocator &metadata_allocator, size_t alignment) | |
| constexpr size_t | num_allocations () const |
| void | SetRegion (ByteSpan region) |
| void * | DoAllocate (allocator::Layout layout) override |
| void | DoDeallocate (void *ptr) override |
| Result< Layout > | DoGetInfo (InfoType info_type, const void *ptr) const override |
| virtual Region * | AllocateRegion (size_t min_size, size_t desired_size)=0 |
| virtual size_t | TryDeallocateRegion (void *ptr)=0 |
Protected Member Functions inherited from pw::Allocator | |
| constexpr | Allocator ()=default |
| TODO(b/326509341): Remove when downstream consumers migrate. | |
| constexpr | Allocator (const Capabilities &capabilities) |
| virtual void * | DoAllocate (Layout layout)=0 |
| virtual bool | DoResize (void *ptr, size_t new_size) |
| virtual void * | DoReallocate (void *ptr, Layout new_layout) |
| virtual size_t | DoGetAllocated () const |
| virtual std::optional< Fragmentation > | DoMeasureFragmentation () const |
| Returns fragmentation information for the allocator's memory region. | |
Protected Member Functions inherited from pw::Deallocator | |
| constexpr | Deallocator ()=default |
| TODO(b/326509341): Remove when downstream consumers migrate. | |
| constexpr | Deallocator (const Capabilities &capabilities) |
| Result< Layout > | GetInfo (InfoType info_type, const void *ptr) const |
| Result< Layout > | GetRequestedLayout (const void *ptr) const |
| Result< Layout > | GetUsableLayout (const void *ptr) const |
| Result< Layout > | GetAllocatedLayout (const void *ptr) const |
| bool | Recognizes (const void *ptr) const |
| virtual void | DoDeallocate (void *ptr)=0 |
| virtual Result< Layout > | DoGetInfo (InfoType, const void *) const |
Additional Inherited Members | |
Public Types inherited from pw::Allocator | |
| using | Fragmentation = allocator::Fragmentation |
Public Types inherited from pw::Deallocator | |
| using | Capabilities = allocator::Capabilities |
| using | Capability = allocator::Capability |
| using | Layout = allocator::Layout |
Protected Types inherited from pw::multibuf::v1_adapter::internal::ChunkAllocator | |
| using | ControlBlock = allocator::internal::ControlBlock |
Protected Types inherited from pw::Deallocator | |
| enum class | InfoType { kRequestedLayoutOf , kUsableLayoutOf , kAllocatedLayoutOf , kCapacity , kRecognizes } |
Static Protected Member Functions inherited from pw::Deallocator | |
| static Result< Layout > | GetInfo (const Deallocator &deallocator, InfoType info_type, const void *ptr) |
| static Result< Layout > | GetRequestedLayout (const Deallocator &deallocator, const void *ptr) |
| static Result< Layout > | GetUsableLayout (const Deallocator &deallocator, const void *ptr) |
| static Result< Layout > | GetAllocatedLayout (const Deallocator &deallocator, const void *ptr) |
| static bool | Recognizes (const Deallocator &deallocator, const void *ptr) |
Static Protected Attributes inherited from pw::Deallocator | |
| template<typename T > | |
| static constexpr bool | is_bounded_array_v = ::pw::is_bounded_array_v<T> |
| template<typename T > | |
| static constexpr bool | is_unbounded_array_v = ::pw::is_unbounded_array_v<T> |
|
overrideprotectedvirtual |
Returns a pointer to a region describing allocated memory of at least min_size and up to desired_size, or null if allocation failed.
Implements pw::multibuf::v1_adapter::internal::ChunkAllocator.
|
inlineprotectedvirtual |
Destroys the ChunkRegionTracker.
Typical implementations will call std::destroy_at(this) and then free the memory associated with the region and the tracker.
Reimplemented in pw::multibuf::v1_adapter::SingleChunkRegionTracker.
|
overrideprotectedvirtual |
Allocates a block of memory with the specified size and alignment.
Returns nullptr if the allocation cannot be made, or the layout has a size of 0.
| [in] | layout | Describes the memory to be allocated. |
Reimplemented from pw::multibuf::v1_adapter::internal::ChunkAllocator.
|
overrideprotectedvirtual |
Releases a previously-allocated block of memory.
The given pointer must have been previously provided by this memory resource; otherwise the behavior is undefined.
| [in] | ptr | Pointer to previously-allocated memory. |
Reimplemented from pw::multibuf::v1_adapter::internal::ChunkAllocator.
| void pw::multibuf::v1_adapter::internal::ChunkAllocator::SetRegion | ( | ByteSpan | region | ) |
Sets the region used to provide chunks.
At most one region may be set by this method or a constructor.
|
overrideprotectedvirtual |
Returns the number of bytes deallocated if the given pointer refers to memory described by a region previously returned by AllocateRegion, or 0 if it does not.
Implements pw::multibuf::v1_adapter::internal::ChunkAllocator.