GRPC C++  1.66.0
Data Structures | Public Member Functions | Protected Member Functions
grpc_event_engine::experimental::MemoryAllocator Class Reference

#include <memory_allocator.h>

Data Structures

class  Container
 A C++ allocator for containers of T. More...
 
class  Reservation
 An automatic releasing reservation of memory. More...
 

Public Member Functions

 MemoryAllocator (std::shared_ptr< internal::MemoryAllocatorImpl > allocator)
 Construct a MemoryAllocator given an internal::MemoryAllocatorImpl implementation. More...
 
 MemoryAllocator ()
 
 ~MemoryAllocator ()
 
 MemoryAllocator (const MemoryAllocator &)=delete
 
MemoryAllocatoroperator= (const MemoryAllocator &)=delete
 
 MemoryAllocator (MemoryAllocator &&)=default
 
MemoryAllocatoroperator= (MemoryAllocator &&)=default
 
void Reset ()
 Drop the underlying allocator and make this an empty object. More...
 
size_t Reserve (MemoryRequest request)
 Reserve bytes from the quota. More...
 
void Release (size_t n)
 Release some bytes that were previously reserved. More...
 
Reservation MakeReservation (MemoryRequest request)
 Reserve bytes from the quota and automatically release them when Reservation is destroyed. More...
 
template<typename T , typename... Args>
std::enable_if< std::has_virtual_destructor< T >::value, T * >::type New (Args &&... args)
 Allocate a new object of type T, with constructor arguments. More...
 
template<typename T , typename... Args>
std::unique_ptr< T > MakeUnique (Args &&... args)
 Construct a unique_ptr immediately. More...
 
grpc_slice MakeSlice (MemoryRequest request)
 Allocate a slice, using MemoryRequest to size the number of returned bytes. More...
 

Protected Member Functions

internal::MemoryAllocatorImplget_internal_impl_ptr ()
 Return a pointer to the underlying implementation. More...
 
const internal::MemoryAllocatorImplget_internal_impl_ptr () const
 

Constructor & Destructor Documentation

◆ MemoryAllocator() [1/4]

grpc_event_engine::experimental::MemoryAllocator::MemoryAllocator ( std::shared_ptr< internal::MemoryAllocatorImpl allocator)
inlineexplicit

Construct a MemoryAllocator given an internal::MemoryAllocatorImpl implementation.

The constructed MemoryAllocator will call MemoryAllocatorImpl::Shutdown() upon destruction.

◆ MemoryAllocator() [2/4]

grpc_event_engine::experimental::MemoryAllocator::MemoryAllocator ( )
inline

◆ ~MemoryAllocator()

grpc_event_engine::experimental::MemoryAllocator::~MemoryAllocator ( )
inline

◆ MemoryAllocator() [3/4]

grpc_event_engine::experimental::MemoryAllocator::MemoryAllocator ( const MemoryAllocator )
delete

◆ MemoryAllocator() [4/4]

grpc_event_engine::experimental::MemoryAllocator::MemoryAllocator ( MemoryAllocator &&  )
default

Member Function Documentation

◆ get_internal_impl_ptr() [1/2]

internal::MemoryAllocatorImpl* grpc_event_engine::experimental::MemoryAllocator::get_internal_impl_ptr ( )
inlineprotected

Return a pointer to the underlying implementation.

Note that the interface of said implementation is unstable and likely to change at any time.

◆ get_internal_impl_ptr() [2/2]

const internal::MemoryAllocatorImpl* grpc_event_engine::experimental::MemoryAllocator::get_internal_impl_ptr ( ) const
inlineprotected

◆ MakeReservation()

Reservation grpc_event_engine::experimental::MemoryAllocator::MakeReservation ( MemoryRequest  request)
inline

Reserve bytes from the quota and automatically release them when Reservation is destroyed.

◆ MakeSlice()

grpc_slice grpc_event_engine::experimental::MemoryAllocator::MakeSlice ( MemoryRequest  request)
inline

Allocate a slice, using MemoryRequest to size the number of returned bytes.

For a variable length request, check the returned slice length to verify how much memory was allocated. Takes care of reserving memory for any relevant control structures also.

◆ MakeUnique()

template<typename T , typename... Args>
std::unique_ptr<T> grpc_event_engine::experimental::MemoryAllocator::MakeUnique ( Args &&...  args)
inline

Construct a unique_ptr immediately.

◆ New()

template<typename T , typename... Args>
std::enable_if<std::has_virtual_destructor<T>::value, T*>::type grpc_event_engine::experimental::MemoryAllocator::New ( Args &&...  args)
inline

Allocate a new object of type T, with constructor arguments.

The returned type is wrapped, and upon destruction the reserved memory will be released to the allocator automatically. As such, T must have a virtual destructor so we can insert the necessary hook.

◆ operator=() [1/2]

MemoryAllocator& grpc_event_engine::experimental::MemoryAllocator::operator= ( const MemoryAllocator )
delete

◆ operator=() [2/2]

MemoryAllocator& grpc_event_engine::experimental::MemoryAllocator::operator= ( MemoryAllocator &&  )
default

◆ Release()

void grpc_event_engine::experimental::MemoryAllocator::Release ( size_t  n)
inline

Release some bytes that were previously reserved.

◆ Reserve()

size_t grpc_event_engine::experimental::MemoryAllocator::Reserve ( MemoryRequest  request)
inline

Reserve bytes from the quota.

If we enter overcommit, reclamation will begin concurrently. Returns the number of bytes reserved.

◆ Reset()

void grpc_event_engine::experimental::MemoryAllocator::Reset ( )
inline

Drop the underlying allocator and make this an empty object.

The object will not be usable after this call unless it's a valid allocator is moved into it.


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