#include <e32cmn.h>
class RHeap : public RAllocator |
Public Member Type Definitions | |
---|---|
typedef | void(* TWalkFunc |
Public Member Enumerations | |
---|---|
enum | anonymous { ECellAlignment } |
enum | anonymous { EFreeCellSize } |
enum | anonymous { EAllocCellSize } |
enum | TCellType { EGoodAllocatedCell, EGoodFreeCell, EBadAllocatedCellSize, EBadAllocatedCellAddress, ..., EBadFreeCellSize } |
enum | TDebugHeapId { EUser, EKernel } |
enum | TDebugOp { EWalk } |
enum | TDefaultShrinkRatios { EShrinkRatio1, EShrinkRatioDflt } |
Public Member Functions | |
---|---|
RHeap(TInt, TInt, TBool) | |
RHeap(TInt, TInt, TInt, TInt, TInt, TInt, TBool) | |
TInt | Align(TInt) |
const TAny * | Align(const TAny *) |
virtual UIMPORT_C TAny * | Alloc(TInt) |
virtual UIMPORT_C TInt | AllocLen(const TAny *) |
virtual UIMPORT_C TInt | AllocSize(TInt &) |
virtual UIMPORT_C TInt | Available(TInt &) |
TUint8 * | Base() |
TInt | ChunkHandle() |
virtual UIMPORT_C TInt | Compress() |
virtual UIMPORT_C TInt | DebugFunction(TInt, TAny *, TAny *) |
virtual UIMPORT_C void | Free(TAny *) |
TBool | IsLastCell(const SCell *) |
void | Lock() |
TInt | MaxLength() |
virtual UIMPORT_C TAny * | ReAlloc(TAny *, TInt, TInt) |
virtual UIMPORT_C void | Reset() |
TInt | Size() |
void | Unlock() |
void | operator delete(TAny *, TAny *) |
UIMPORT_C TAny * | operator new(TUint, TAny *) |
Protected Member Functions | |
---|---|
RHeap() | |
void | CheckCell(const SCell *) |
TBool | CheckForSimulatedAllocFail() |
SCell * | DoAlloc(TInt, SCell *&) |
TInt | DoCheckHeap(SCheckInfo *) |
TInt | DoCountAllocFree(TInt &) |
void | DoFree(SCell *) |
TUint32 | DoMarkEnd(TInt) |
void | DoMarkStart() |
void | DoSetAllocFail(TAllocFail, TInt) |
void | DoSetAllocFail(TAllocFail, TInt, TUint) |
virtual UIMPORT_C TInt | Extension_(TUint, TAny *&, TAny *) |
void | FindFollowingFreeCell(SCell *, SCell *&, SCell *&) |
UIMPORT_C SCell * | GetAddress(const TAny *) |
void | Initialise() |
TAny * | ReAllocImpl(TAny *, TInt, TInt) |
TInt | Reduce(SCell *) |
TInt | SetBrk(TInt) |
TInt | TryToGrowCell(SCell *, SCell *, SCell *, TInt) |
TInt | TryToGrowHeap(TInt, SCell *) |
void | Walk(TWalkFunc, TAny *) |
void | WalkCheckCell(TAny *, TCellType, TAny *, TInt) |
Inherited Attributes | |
---|---|
RAllocator::iAccessCount | |
RAllocator::iCellCount | |
RAllocator::iFlags | |
RAllocator::iHandleCount | |
RAllocator::iHandles | |
RAllocator::iTotalAllocSize |
Inherited Enumerations | |
---|---|
RAllocator:@10 | |
RAllocator:TAllocDebugOp | |
RAllocator:TAllocFail | |
RAllocator:TDbgHeapType | |
RAllocator:TFlags | |
RAllocator:TReAllocMode |
Represents the default implementation for a heap.
The default implementation uses an address-ordered first fit type algorithm.
The heap itself is contained in a chunk and may be the only occupant of the chunk or may share the chunk with the program stack.
The class contains member functions for allocating, adjusting, freeing individual cells and generally managing the heap.
The class is not a handle in the same sense that RChunk is a handle; i.e. there is no Kernel object which corresponds to the heap.
Reimplemented from MAllocator::Alloc(TInt)
Allocates a cell of the specified size from the heap.
If there is insufficient memory available on the heap from which to allocate a cell of the required size, the function returns NULL.
The cell is aligned according to the alignment value specified at construction, or the default alignment value, if an explict value was not specified.
The resulting size of the allocated cell may be rounded up to a value greater than aSize, but is guaranteed to be not less than aSize.
See also: KMaxTInt
Parameter | Description |
---|---|
aSize | The size of the cell to be allocated from the heap |
Returns: A pointer to the allocated cell. NULL if there is insufficient memory available.
Reimplemented from MAllocator::AllocLen(const TAny *)const
Gets the length of the available space in the specified allocated cell.
Parameter | Description |
---|---|
aCell | A pointer to the allocated cell. |
Returns: The length of the available space in the allocated cell.
Reimplemented from MAllocator::AllocSize(TInt &)const
Gets the number of cells allocated on this heap, and the total space allocated to them.
Parameter | Description |
---|---|
aTotalAllocSize | On return, contains the total space allocated to the cells. |
Returns: The number of cells allocated on this heap.
Reimplemented from MAllocator::Available(TInt &)const
Gets the total free space currently available on the heap and the space available in the largest free block.
The space available represents the total space which can be allocated.
Note that compressing the heap may reduce the total free space available and the space available in the largest free block.
Parameter | Description |
---|---|
aBiggestBlock | On return, contains the space available in the largest free block on the heap. |
Returns: The total free space currently available on the heap.
TUint8 * | Base | ( | ) | const [inline] |
Gets a pointer to the start of the heap.
Note that because of the small space overhead incurred by all allocated cells, no cell will have the same address as that returned by this function.
Returns: A pointer to the base of the heap.
UIMPORT_C TInt | Compress | ( | ) | [virtual] |
Reimplemented from MAllocator::Compress()
Compresses the heap.
The function frees excess committed space from the top of the heap. The size of the heap is never reduced below the minimum size specified during creation of the heap.
Returns: The space reclaimed. If no space can be reclaimed, then this value is zero.
Reimplemented from MAllocator::DebugFunction(TInt,TAny *,TAny *)
void | DoSetAllocFail | ( | TAllocFail | aType, |
TInt | aRate, | |||
TUint | aBurst | |||
) | [protected] |
Reimplemented from RAllocator::Extension_(TUint,TAny *&,TAny *)
UIMPORT_C void | Free | ( | TAny * | aPtr | ) | [virtual] |
Reimplemented from MAllocator::Free(TAny *)
Frees the specified cell and returns it to the heap.
Parameter | Description |
---|---|
aPtr | A pointer to a valid cell; this pointer can also be NULL, in which case the function does nothing and just returns. |
Reimplemented from MAllocator::ReAlloc(TAny *,TInt,TInt)
Increases or decreases the size of an existing cell in the heap.
If the cell is being decreased in size, then it is guaranteed not to move, and the function returns the pointer originally passed in aCell. Note that the length of the cell will be the same if the difference between the old size and the new size is smaller than the minimum cell size.
If the cell is being increased in size, i.e. aSize is bigger than its current size, then the function tries to grow the cell in place. If successful, then the function returns the pointer originally passed in aCell. If unsuccessful, then:
1. if the cell cannot be moved, i.e. aMode has the ENeverMove bit set, then the function returns NULL. 2. if the cell can be moved, i.e. aMode does not have the ENeverMove bit set, then the function tries to allocate a new replacement cell, and, if successful, returns a pointer to the new cell; if unsuccessful, it returns NULL.
Note that in debug mode, the function returns NULL if the cell cannot be grown in place, regardless of whether the ENeverMove bit is set.
If the reallocated cell is at a different location from the original cell, then the content of the original cell is copied to the reallocated cell.
If the supplied pointer, aCell is NULL, then the function attempts to allocate a new cell, but only if the cell can be moved, i.e. aMode does not have the ENeverMove bit set.
Note the following general points:
1. If reallocation fails, the content of the original cell is preserved.
2. The resulting size of the re-allocated cell may be rounded up to a value greater than aSize, but is guaranteed to be not less than aSize.
See also: RAllocator::TReAllocMode
Parameter | Description |
---|---|
aPtr | A pointer to the cell to be reallocated. This may be NULL. |
aSize | The new size of the cell. This may be bigger or smaller than the size of the original cell. |
aMode | Flags controlling the reallocation. The only bit which has any effect on this function is that defined by the enumeration ENeverMove of the enum RAllocator::TReAllocMode. If this is set, then any successful reallocation guarantees not to have changed the start address of the cell. By default, this parameter is zero. |
Returns: A pointer to the reallocated cell. This may be the same as the original pointer supplied through aCell. NULL if there is insufficient memory to reallocate the cell, or to grow it in place.
UIMPORT_C void | Reset | ( | ) | [virtual] |
Reimplemented from MAllocator::Reset()
Frees all allocated cells on this heap.
TInt | Size | ( | ) | const [inline] |
Gets the current size of the heap.
This is the total number of bytes committed by the host chunk. It is the requested size rounded up by page size minus the size of RHeap object(116 bytes) minus the cell alignment overhead as shown:
Size = (Rounded committed size - Size of RHeap - Cell Alignment Overhead).
The cell alignment overhead varies between release builds and debug builds.
Note that this value is always greater than the total space available across all allocated cells.
See also: Rheap::Available( )
Returns: The size of the heap.
Called if constructor issued by operator new(TUint aSize, TAny* aBase) throws exception. This is dummy as corresponding new operator does not allocate memory.