BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlma::GuardingAllocator Class Reference

#include <bdlma_guardingallocator.h>

Inheritance diagram for bdlma::GuardingAllocator:
bslma::Allocator bsl::memory_resource

Public Types

enum  GuardPageLocation { e_AFTER_USER_BLOCK , e_BEFORE_USER_BLOCK }
 
- Public Types inherited from bslma::Allocator
typedef std::size_t size_type
 

Public Member Functions

 GuardingAllocator (GuardPageLocation guardLocation=e_AFTER_USER_BLOCK)
 
 ~GuardingAllocator () BSLS_KEYWORD_OVERRIDE
 
void * allocate (bsls::Types::size_type size) BSLS_KEYWORD_OVERRIDE
 
void deallocate (void *address) BSLS_KEYWORD_OVERRIDE
 
- Public Member Functions inherited from bslma::Allocator
 ~Allocator () BSLS_KEYWORD_OVERRIDE
 
template<class TYPE >
void deleteObject (const TYPE *object)
 
template<class TYPE >
void deleteObjectRaw (const TYPE *object)
 
void deleteObject (bsl::nullptr_t)
 
void deleteObjectRaw (bsl::nullptr_t)
 
- Public Member Functions inherited from bsl::memory_resource
 memory_resource () BSLS_KEYWORD_DEFAULT
 Create this object. Has no effect other than to begin its lifetime.
 
 memory_resource (const memory_resource &) BSLS_KEYWORD_DEFAULT
 
virtual ~memory_resource ()
 Destroy this object. Has no effect other than to end its lifetime.
 
memory_resourceoperator= (const memory_resource &) BSLS_KEYWORD_DEFAULT
 Return a modifiable reference to this object.
 
BSLS_ANNOTATION_NODISCARD void * allocate (size_t bytes, size_t alignment=k_MAX_ALIGN)
 
void deallocate (void *p, size_t bytes, size_t alignment=k_MAX_ALIGN)
 
bool is_equal (const memory_resource &other) const BSLS_KEYWORD_NOEXCEPT
 

Additional Inherited Members

- Static Public Member Functions inherited from bslma::Allocator
static void throwBadAlloc ()
 
- Protected Member Functions inherited from bslma::Allocator
void * do_allocate (std::size_t bytes, std::size_t alignment) BSLS_KEYWORD_OVERRIDE
 
void do_deallocate (void *p, std::size_t bytes, std::size_t alignment) BSLS_KEYWORD_OVERRIDE
 
bool do_is_equal (const memory_resource &other) const BSLS_KEYWORD_NOEXCEPT BSLS_KEYWORD_OVERRIDE
 

Detailed Description

This class defines a concrete thread-safe "guarding" allocator mechanism that implements the bslma::Allocator protocol, and adjoins a read/write protected guard page to each block of memory returned by the allocate method. The guard page is placed immediately before or immediately following the block returned from allocate according to the GuardPageLocation enumerator value (optionally) supplied at construction. Note that, unlike many other allocators, an allocator cannot be (optionally) supplied at construction; instead, a system facility is used that allocates blocks of memory in multiples of the system page size. Also note that this allocator is intended for debugging purposes only.

See bdlma_guardingallocator

Member Enumeration Documentation

◆ GuardPageLocation

Enumerator
e_AFTER_USER_BLOCK 
e_BEFORE_USER_BLOCK 

Constructor & Destructor Documentation

◆ GuardingAllocator()

bdlma::GuardingAllocator::GuardingAllocator ( GuardPageLocation  guardLocation = e_AFTER_USER_BLOCK)
inlineexplicit

Create a guarding allocator. Optionally specify a guardLocation indicating where read/write protected guard pages should be placed with respect to the memory blocks returned by the allocate method. If guardLocation is not specified, guard pages are placed immediately following the memory blocks returned by allocate.

◆ ~GuardingAllocator()

bdlma::GuardingAllocator::~GuardingAllocator ( )

Destroy this allocator object. Note that destroying this allocator has no effect on any outstanding allocated memory.

Member Function Documentation

◆ allocate()

void * bdlma::GuardingAllocator::allocate ( bsls::Types::size_type  size)
virtual

Return a newly-allocated maximally-aligned block of memory of the specified size (in bytes) that has a read/write protected guard page located immediately before or after it according to the GuardPageLocation indicated at construction. If size is 0, no memory is allocated and 0 is returned. Note that a multiple of the platform's memory page size is allocated for every call to this method.

Implements bslma::Allocator.

◆ deallocate()

void bdlma::GuardingAllocator::deallocate ( void *  address)
virtual

Return the memory block at the specified address back to this allocator. If address is 0, this method has no effect. Otherwise, the guard page associated with address is unprotected and also deallocated. The behavior is undefined unless address was returned by allocate and has not already been deallocated.

Implements bslma::Allocator.


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