Logo Search packages:      
Sourcecode: maxdb-7.5.00 version File versions

SAPDBMem_RawAllocator Class Reference

#include <SAPDBMem_RawAllocator.hpp>

Inheritance diagram for SAPDBMem_RawAllocator:

SAPDBMem_IRawAllocator SAPDBMem_IAllocatorInfo LVCMem_EmergencyAllocator SAPDBMem_SynchronizedRawAllocator

List of all members.

Detailed Description

Implementation of the 'SAPDBMem_IRawAllocator' interface. This class provides an implementation of a heap based on the ideas of the malloc/free/realloc written by Doug Lea.

According to Lea the algorithm is among the fastest while also being among the most space-conserving, portable and tunable. Consistent balance across these factors results in a good general-purpose allocator. For a high-level description, see http://g.oswego.edu/dl/html/malloc.html The following changes have been made:

Definition at line 148 of file SAPDBMem_RawAllocator.hpp.

Public Types

typedef CChunkCChunkPtr
 a pointer to a chunk
typedef SAPDB_UInt4 ChunkSize
 chunk size
typedef SAPDB_ULong SizeType
 size type of the interface

Public Member Functions

virtual void * Allocate (SAPDB_ULong ByteCount, const void *Hint)
 allocates ByteCount bytes from allocator
virtual void * Allocate (SAPDB_ULong ByteCount)
 allocates ByteCount bytes from allocator
HeapIterator Begin ()
 yields an iterator over all memory chunks of the allocator.
virtual void CalcStatistics (SAPDB_ULong &BytesUsed, SAPDB_ULong &MaxBytesUsed, SAPDB_ULong &BytesControlled)
 yieds allocator statistics
void CalcStatisticsConst (SAPDB_ULong &BytesUsed, SAPDB_ULong &MaxBytesUsed, SAPDB_ULong &BytesControlled) const
 yieds allocator statistics
bool Check ()
 checks allocator integrity
virtual bool CheckConsistency ()
 checks allocator integrity
virtual void Deallocate (void *p)
 deallocates (frees) a chunk previously returned by an Allocate call.
void DisableOpMessages ()
 normally in the kernel context information is written into the knldiag file, if the allocator runs out of memory. After a call of DisableOpMessages disables the behavior.
virtual void FreeAll ()
 See 'SAPDBMem_IRawAllocator'.
RTEMem_AllocatorInfo & GetAllocatorInfo ()
 returns the allocator info of allocator (name, pointer to raw allocator interface, name of underlying allocator.
virtual void GetBaseAllocatorCallStatistics (SAPDB_ULong &CountAlloc, SAPDB_ULong &CountDealloc) const
 yields statistics about calls to base allocator
int GetCallStackLevel () const
 returns the current call stack level (monitoring of chunk owners)
virtual void GetCallStatistics (SAPDB_ULong &CountAlloc, SAPDB_ULong &CountDealloc) const
 yields statistics about Allocate and Deallocate calls
void GetChunkInfo (const void *p, bool &inUse, SAPDB_ULong &ChunkSize, SAPDB_ULong &CallStackId) const
 yields information about a memory chunk
virtual SAPDB_ULong GetChunkSize (const void *p)
 returns the size of a chunk
virtual int GetErrorCount () const
 Returns the number of errors found and corrected by the allocator.
SAPDB_UInt4 GetFirstChunkParameter () const
 returns the minimal size of the first chunk allocated from the underlying allocator
virtual const SAPDB_UTF8 * GetIdentifier () const
 returns the name of the allocator.
void GetInfo (THeapInfo &info) const
 yields information about heap occupancy
bool IsWriteProtected () const
 returns true if write protection is enables, false otherwise
bool operator!= (SAPDBMem_IRawAllocator &Other)
 Returns the opposite of operator ==.
bool operator== (SAPDBMem_IRawAllocator &Other)
 Compares two raw allocator instances.
void * Reallocate (SAPDB_ULong ByteCount, void *hint)
 has same semantics as C runtime realloc
 SAPDBMem_RawAllocator (const SAPDB_UTF8 *Identifier, SAPDBMem_IBlockAllocator &BlockAllocator, RTESync_Spinlock *lockObject, SAPDB_ULong FirstBlockSize, SAPDB_ULong SupplementBlockSize, FreeRawExtendsEnum FreeRawExtends, SAPDB_ULong MaxSize=SAPDBMEM_ALLOCATOR_UNLIMITED)
 Constructs an allocator from the provided RawAllocator or BlockAllocator.
 SAPDBMem_RawAllocator (const SAPDB_UTF8 *Identifier, SAPDBMem_IBlockAllocator &BlockAllocator, SAPDB_ULong FirstBlockSize, SAPDB_ULong SupplementBlockSize, FreeRawExtendsEnum FreeRawExtends, SAPDB_ULong MaxSize=SAPDBMEM_ALLOCATOR_UNLIMITED)
 Constructs an allocator from the provided RawAllocator or BlockAllocator.
 SAPDBMem_RawAllocator (const SAPDB_UTF8 *Identifier, SAPDBMem_IRawAllocator &RawAllocator, SAPDB_ULong FirstBlockSize, SAPDB_ULong SupplementBlockSize, FreeRawExtendsEnum FreeRawExtends, SAPDB_ULong MaxSize=SAPDBMEM_ALLOCATOR_UNLIMITED, bool DoRegister=true)
 Constructs an allocator from the provided RawAllocator or BlockAllocator.
void SetBadAllocHandler (BadAllocHandlers handler)
 enables the handler to be used when no more memory is available
void SetCallStackMonitoring (int level)
 enables or disables call stack monitoring. If call stack monitoring is enabled, each memory chunk contains information about the call stack of the memory request.
void SetCheckLevel ()
 enables all check levels of the allocator according to parameter HEAP_CHECK_LEVEL.
void SetFullChecking ()
 enables all check levels of the allocator. caution : has no meaning, if the allocator holds any memory
void SetIdentifier (const SAPDB_UTF8 *Name)
 set the name of the allocator
void SetLimit (SAPDB_ULong NewLimit)
 sets the maximal size of the total memory in bytes controlled by the RawAllocator. Has no meaning, if the current size is already greater than NewLimit.
void SetSupplementChunkParameter (SAPDB_UInt4)
 sets the size of memory required from the base allocator
void SetTracer (ITracerAndExceptionHandler *pTracer)
 sets the tracer to be used for tracing and exception handling
bool Unprotect ()
 enables read and write access to data managed by the allocator
bool WriteProtect ()
 disables any changes in memory managed by the allocator. This is possible only if the allocator is based on a block alloctor.
virtual ~SAPDBMem_RawAllocator ()
 destructor, returns all memory to base allocator

Static Public Member Functions

static SAPDB_ULong CalcAlignmentOffset (void *Address)
 Returns the offset of <Address> to the next address which is greater than <Address> and is aligned.
static SAPDB_ULong GetAlignmentSize ()
 Returns the alignment size in bytes of this allocator.
static SAPDBMem_RawAllocatorGetAllocator (const void *p)
 for a given memory chunk provided from a SAPDBMem_RawAllocator instance a pointer to that instance is returned.
static int GetChunkProperties (const void *p)
 returns the properties of a memory chunk. These properties have been set by a previous call of SetChunkProperties.
static SAPDB_ULong GetInvalidSize ()
 Returns the value for an invalid size. The is defined as 0xFFFF... .
static bool IsAligned (void *Address)
 Checks, if the given address is aligned.
static void SetAllocator (void *p, SAPDBMem_IRawAllocator *pAllocator)
 stores a pointer to an allocator into a memory chunk. The memory chunk must have been provided by a call of SAPDBMem_RawAllocator::Allocate.
static void SetChunkProperties (const void *p, int properties)
 each memory chunk managed by a SAPDBMem_RawAllocator instance may hold up to 3 bits of property information, that can be set by the holder of the chunk. The chunk properties have no meaning for the SAPDBMem_RawAllocator, but only for the chunk owner. The properties of a chunk may be requested via GetChunkProperties

Protected Member Functions

INLINE void DecrementAllocated (ChunkSize decrement)
INLINE void DecrementUsed (ChunkSize decrement)
INLINE void IncrementAllocated (ChunkSize increment)
INLINE void IncrementAllocCnt ()
INLINE void IncrementDeallocCnt ()
INLINE void IncrementRawAllocCnt ()
INLINE void IncrementRawDeallocCnt ()
INLINE void IncrementUsed (ChunkSize increment)

Private Types

typedef SAPDBMem_TreeNode * NodePtr
 Node of the tree managing big free chunks.

Private Member Functions

INLINE void * AllocateResult (CChunk *pChunk, int monitorCallStackLevel)
 returns the result of an Allocate call
bool AnalyzeAllocator (void *p)
 checks the consistence of the allocator
INLINE void Assert (bool condtion)
 asserts a condition
typedef void *() BadAllocFunc (SAPDB_ULong)
 signature of a bad alloc handler
void CheckConstraints ()
 checks the allocator constraints, check in the course of construction
INLINE bool CheckFreeChunk (CChunkPtr pChunk)
 checks state of a free chunk
INLINE void CheckNoMansLand (CChunkPtr pChunk)
 checks the no mans land pattern
bool CheckPointer (void *p, bool abort=true)
 verifies a pointer, must lie in any raw chunk
void DeallocateRaw (void *p, SAPDB_ULong BlockCount)
 returns memory to the base allocator
void Destructor ()
 destructs the allocator
void Dump ()
 dumps the allocator using m_tracer
void DumpChunk (void *p, int length)
 dumps a chunk using m_tracer
INLINE void FillFreeChunk (void *p, int offset, int size, SAPDB_UInt4 pattern)
 fille a chunk with given pattern
void FreeRawChunk (SAPDBMem_RawAllocator::CChunkPtr endChunk, SAPDBMem_RawAllocator::CChunkPtr p)
 free a raw chunk
INLINE void FrontLink (CChunkPtr pChunk, ChunkSize sz)
 inserts a chunk into free list
INLINE IteratorStateGetIteratorState ()
 returns the current iterator state
INLINE SAPDB_UInt4 Idx2BinBlock (int)
void InsertChunkIntoSortedList (CChunkPtr pChunk)
 inserts a chunk into a sorted list ordered by chunk size
INLINE void InsertFreeBigChunk (CChunkPtr p)
 inserts a big free cunks into the tree managing big chunks
bool MallocExtend (ChunkSize required)
 required memory from the base allocator
INLINE void MarkBinBlock (int)
 marks a bin block as containing free blocks
void NewNodeBuffer ()
 requests a new buffer for nodes of tree managing big chunks
SAPDBMem_RawAllocator operator= (SAPDBMem_RawAllocator &)
 Private assignment operator avoids copying.
bool Protect (SAPDB_Int mode)
 support for memory write protection
INLINE void RemoveFreeBigChunk (CChunkPtr p)
 removes a chunk from the tree managing big chunks
 SAPDBMem_RawAllocator (const SAPDBMem_RawAllocator &InitAlloc)
 Private copy constructor avoids copying.
void SubTreeCheck (NodePtr p, NodePtr *followed)
 checks a subtree of the tree managing big chunks for consistency
void ThrowException ()
 throws an exception
void Trace (const char *msg,...)
 writes a message into trace
void TraceRawChunks ()
 writes information of all base chunks into trace
void TraceSubTree (NodePtr p)
 writes information of big free chunks into knldiag
void TraceTree ()
 writes information of big free chunks into knldiag
void TreeCheck ()
 checks a tree of the tree managing big chunks for consistency
INLINE bool TreeFindFreeChunk (CChunkPtr p)
 searches a chunk in the tree managing big chunks
INLINE void TreeRemoveNode (NodePtr pNode)
 removes a node from the tree managing big chunks

Static Private Member Functions

static INLINE ChunkSize AlignedSize (ChunkSize req)
 returns the aligned size of a given size
static void * BadAllocNoThrow (SAPDB_ULong)
 handler for bad alloc without throw (returns null)
static void * BadAllocThrowSAPDBMem_BadAlloc (SAPDB_ULong)
 handler for bad alloc throwing SAPDBMem_Exception
static void * BadAllocThrowStdBadAlloc (SAPDB_ULong)
 handler for bad alloc throwing std::bad_alloc
static SAPDB_UInt4 GetCheckLevel ()
 return the current check level
static BadAllocFunc * InitBadAllocHandler ()
 returns the initial bad alloc handler
static bool IsSmallRequest (ChunkSize req)
 returns true, if req identifies a small request
static int RawChunkHeaderSize ()
 returns the size of a base chunk

Private Attributes

RTEMem_AllocatorInfo m_AllocatorInfo
 allocator statistics
BadAllocFunc * m_badAllocFunc
 current bad alloc handler
SAPDB_UInt4 m_binBlocks
 index of free lists containing free chunks
 underlying block allocator, may be NULL
SAPDB_UInt4 m_checkFlags
 current allocator check levels
bool m_checkHeap
 check heap if true
bool m_doUnregister
 true, if allocator has to be unregistered at destruction
int m_errorCount
 numbers of error detected
void * m_filler
 filler to ensure chunk layout
NodePtr m_firstFreeNode
 pointer to first free node of tree managing big chunks
SizeType m_firstSize
 size of the first base chunk
CFreeChunkLists m_freeLists
 free lists of small chunks
TNodeBuffer * m_freeNodeBuffer
 pointer to buffer providing nodes of tree managing big chunks
FreeRawExtendsEnum m_freeRawExtends
 return free base chunks to base allocator ?
THeapInfo m_heapInfo
 allocator statistics
IteratorState m_iterState
 current iterator state
 synchronisation object, may be NULL
SizeType m_maxHeap
 maximal memory (in bytes) required from base allocator
int m_monitorCallStackLevel
 depth of back trace
SAPDB_UTF8 m_Name [40+1]
 name of the allocator
CChunkPtr m_next
 next to ensure chunk layout
bool m_opMessages
 if true, op messages are written to the knldiag in error conditions
CChunkPtr m_prev
 prev to ensure chunk layout
 underlying raw allocator, may be NULL
< SAPDBMem_RawChunkHeader,
 tree managing big free chunks
SAPDBMem_RawChunkTreeComparator m_rawChunkTreeComparator
 comparator for tree managing big chunks
SAPDBMem_RawChunkTreeAllocator m_rawTreeAllocator
 allocator for tree managing big chunks
NodePtr m_root
 root to the tree managing big chunks
SizeType m_supplement
 size of base chunk required from base allocator
 pointer to an instance providing tracer inderface
SAPDBMem_UsedChunkDirectory * m_usedChunks
 used chunk directory, only if double bookkeeping is enabled
bool m_writeProtected
 true if allocator is write protected


class SAPDBMem_RawAllocator::CChunk
 forward declaration of CChunk, defined in implementation
class SAPDBMem_RawAllocator::CFreeChunkLists
class SAPDBMem_RawAllocator::HeapIterator
struct SAPDBMem_RawChunkHeader


class  CChunk
class  CFreeChunkLists
 manages free chunks More...
class  HeapIterator
 defines an heap iterator. The iterator allows to seek out all chunks (free and used) of the heap. More...
struct  IteratorState
 contains the current state of an iterator More...
class  ITracerAndExceptionHandler
struct  THeapInfo
 structure keeping track of heap occupancy More...
struct  TNodeBuffer

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

Generated by  Doxygen 1.6.0   Back to index