UserHeap Class Reference

#include <e32std.h>

class UserHeap
Public Member Enumerations
enumTChunkHeapCreateMode { EChunkHeapSwitchTo, EChunkHeapDuplicate, EChunkHeapMask }
Public Member Functions
IMPORT_C RHeap *ChunkHeap(const TDesC *, TInt, TInt, TInt, TInt, TBool)
IMPORT_C RHeap *ChunkHeap(RChunk, TInt, TInt, TInt, TInt, TBool, TUint32)
IMPORT_C RHeap *ChunkHeap(const TChunkHeapCreateInfo &)
IMPORT_C RHeap *ChunkHeap(const TChunkHeapCreateInfo &, const THeapConfigParms &)
IMPORT_C TIntCreateThreadHeap(SStdEpocThreadCreateInfo &, RHeap *&, TInt, TBool)
IMPORT_C RHeap *FixedHeap(TAny *, TInt, TInt, TBool)
IMPORT_C RHeap *OffsetChunkHeap(RChunk, TInt, TInt, TInt, TInt, TInt, TBool, TUint32)
IMPORT_C TIntSetupThreadHeap(TBool, SStdEpocThreadCreateInfo &)

Member Enumeration Documentation

Enum TChunkHeapCreateMode

Flags to control the heap creation.

EnumeratorValueDescription
EChunkHeapSwitchTo0x1

On successful creation of the heap this switches the calling thread to use the new heap.

EChunkHeapDuplicate0x2

On successful creation of the heap this causes the handle to the heap to be duplicated.

EChunkHeapMaskEChunkHeapSwitchTo | EChunkHeapDuplicate

Member Function Documentation

ChunkHeap ( const TDesC *, TInt, TInt, TInt, TInt, TBool )

IMPORT_C RHeap *ChunkHeap(const TDesC *aName,
TIntaMinLength,
TIntaMaxLength,
TIntaGrowBy = 1,
TIntaAlign = 0,
TBoolaSingleThread = EFalse
)[static]

Creates a heap in a local or global chunk.

The chunk hosting the heap can be local or global.

A local chunk is one which is private to the process creating it and is not intended for access by other user processes. A global chunk is one which is visible to all processes.

The hosting chunk is local, if the pointer aName is NULL, otherwise the hosting chunk is global and the descriptor *aName is assumed to contain the name to be assigned to it.

Ownership of the host chunk is vested in the current process.

A minimum and a maximum size for the heap can be specified. On successful return from this function, the size of the heap is at least aMinLength. If subsequent requests for allocation of memory from the heap cannot be satisfied by compressing the heap, the size of the heap is extended in increments of aGrowBy until the request can be satisfied. Attempts to extend the heap causes the size of the host chunk to be adjusted.

Note that the size of the heap cannot be adjusted by more than aMaxLength.

Parameters
aNameIf NULL, the function constructs a local chunk to host the heap. If not NULL, a pointer to a descriptor containing the name to be assigned to the global chunk hosting the heap.
aMinLengthThe minimum length of the heap in bytes. This will be rounded up to the nearest page size by the allocator.
aMaxLengthThe maximum length in bytes to which the heap can grow. This will be rounded up to the nearest page size by the allocator.
aGrowByThe number of bytes by which the heap will grow when more memory is required. This will be rounded up to the nearest page size by the allocator. If a value is not explicitly specified, the page size is taken by default.
aAlignFrom Symbian^4 onwards, this value is ignored but EABI 8 byte alignment is guaranteed for all allocations 8 bytes or more in size. 4 byte allocations will be aligned to a 4 byte boundary. Best to pass in zero.
aSingleThreadEFalse if the heap is to be accessed from multiple threads. This will cause internal locks to be created, guaranteeing thread safety.
Return Value
A pointer to the new heap or NULL if the heap could not be created.
Panic Codes
USER41 if aMaxLength is < aMinLength.
USER55 if aMinLength is negative.
USER56 if aMaxLength is negative.

ChunkHeap ( RChunk, TInt, TInt, TInt, TInt, TBool, TUint32 )

IMPORT_C RHeap *ChunkHeap(RChunkaChunk,
TIntaMinLength,
TIntaGrowBy = 1,
TIntaMaxLength = 0,
TIntaAlign = 0,
TBoolaSingleThread = EFalse,
TUint32aMode = 0
)[static]

Creates a heap in an existing chunk.

This function is intended to be used to create a heap in a user writable code chunk as created by a call to RChunk::CreateLocalCode(). This type of heap can be used to hold code fragments from a JIT compiler.

See also: UserHeap::OffsetChunkHeap()

Parameters
aChunkThe chunk that will host the heap.
aMinLengthThe minimum length of the heap in bytes. This will be rounded up to the nearest page size by the allocator.
aGrowByThe number of bytes by which the heap will grow when more memory is required. This will be rounded up to the nearest page size by the allocator. If a value is not explicitly specified, the page size is taken by default.
aMaxLengthThe maximum length in bytes to which the heap can grow. This will be rounded up to the nearest page size by the allocator. If 0 is passed in, the maximum lengt of the chunk is used.
aAlignFrom Symbian^4 onwards, this value is ignored but EABI 8 byte alignment is guaranteed for all allocations 8 bytes or more in size. 4 byte allocations will be aligned to a 4 byte boundary. Best to pass in zero.
aSingleThreadEFalse if the heap is to be accessed from multiple threads. This will cause internal locks to be created, guaranteeing thread safety.
aModeFlags controlling the heap creation. See RAllocator::TFlags.
Return Value
A pointer to the new heap or NULL if the heap could not be created.

ChunkHeap ( const TChunkHeapCreateInfo & )

IMPORT_C RHeap *ChunkHeap(const TChunkHeapCreateInfo &aCreateInfo)[static]

Creates a chunk heap of the type specified by the parameter aCreateInfo.

Parameters
aCreateInfoA reference to a TChunkHeapCreateInfo object specifying the type of chunk heap to create.
Return Value
A pointer to the new heap or NULL if the heap could not be created.
Panic Codes
USER41 if the heap's specified minimum length is greater than the specified maximum length.
USER55 if the heap's specified minimum length is negative.
USER172 if the heap's specified alignment is not a power of 2 or is less than the size of a TAny*.

ChunkHeap ( const TChunkHeapCreateInfo &, const THeapConfigParms & )

IMPORT_C RHeap *ChunkHeap(const TChunkHeapCreateInfo &aCreateInfo,
const THeapConfigParms &aConfigParms
)[static]

Creates a chunk heap of the type specified by the parameters aCreateInfo and aConfigParms.

Parameters
aCreateInfoA reference to a TChunkHeapCreateInfo object specifying the type of chunk heap to create.
aConfigParmsA reference to a THeapConfigParms object specifying the parameters depending on the heap type.
Return Value
A pointer to the new heap or NULL if the heap could not be created.
Panic Codes
USER41 if the heap's specified minimum length is greater than the specified maximum length.
USER55 if the heap's specified minimum length is negative.
USER172 if the heap's specified alignment is not a power of 2 or is less than the size of a TAny*.

CreateThreadHeap ( SStdEpocThreadCreateInfo &, RHeap *&, TInt, TBool )

IMPORT_C TIntCreateThreadHeap(SStdEpocThreadCreateInfo &aInfo,
RHeap *&aHeap,
TIntaAlign = 0,
TBoolaSingleThread = EFalse
)[static]

FixedHeap ( TAny *, TInt, TInt, TBool )

IMPORT_C RHeap *FixedHeap(TAny *aBase,
TIntaMaxLength,
TIntaAlign = 0,
TBoolaSingleThread = ETrue
)[static]

Creates a fixed length heap at a specified location.

On successful return from this function, the heap is ready to use. This assumes that the memory pointed to by aBase is mapped and able to be used. You must ensure that you pass in a large enough value for aMaxLength. Passing in a value that is too small to hold the metadata for the heap (~1 KB) will result in the size being rounded up and the heap thereby running over the end of the memory assigned to it. But then if you were to pass in such as small value then you would not be able to do any allocations from the heap anyway. Moral of the story: Use a sensible value for aMaxLength!

Parameters
aBaseA pointer to the location where the heap is to be constructed.
aMaxLengthThe maximum length in bytes to which the heap can grow. If the supplied value is too small to hold the heap's metadata, it will be increased.
aAlignFrom Symbian^4 onwards, this value is ignored but EABI 8 byte alignment is guaranteed for all allocations 8 bytes or more in size. 4 byte allocations will be aligned to a 4 byte boundary. Best to pass in zero.
aSingleThreadEFalse if the heap is to be accessed from multiple threads. This will cause internal locks to be created, guaranteeing thread safety.
Return Value
A pointer to the new heap, or NULL if the heap could not be created.
Panic Codes
USER56 if aMaxLength is negative.

OffsetChunkHeap ( RChunk, TInt, TInt, TInt, TInt, TInt, TBool, TUint32 )

IMPORT_C RHeap *OffsetChunkHeap(RChunkaChunk,
TIntaMinLength,
TIntaOffset,
TIntaGrowBy = 1,
TIntaMaxLength = 0,
TIntaAlign = 0,
TBoolaSingleThread = EFalse,
TUint32aMode = 0
)[static]

Creates a heap in an existing chunk, offset from the beginning of the chunk.

This function is intended to be used to create a heap using a chunk which has some of its memory already used, at the start of that that chunk. The maximum length to which the heap can grow is the maximum size of the chunk, minus the data at the start of the chunk.

The offset at which to create the heap is passed in as the aOffset parameter. Legacy heap implementations always respected the aOffset value, however more modern heap implementations are more sophisticated and cannot necessarily respect this value. Therefore, if possible, you should always use an aOffset of 0 unless you have a very explicit requirement for using a non zero value. Using a non zero value will result in a less efficient heap algorithm being used in order to respect the offset.

Another issue to consider when using this function is the type of the chunk passed in. In order for the most efficient heap algorithms to be used, the chunk passed in should always be a disconnected chunk. Passing in a non disconnected chunk will again result in a less efficient heap algorithm being used.

Finally, another requirement for the most efficient heap algorithms to be used is for the heap to be able to expand. Therefore, unless you have a specific reason to do so, always specify aMaxLength > aMinLength.

So, if possible, use aOffset == zero, aMaxLength > aMinLength and a disconnected chunk for best results!

Parameters
aChunkThe chunk that will host the heap.
aMinLengthThe minimum length of the heap in bytes. This will be rounded up to the nearest page size by the allocator.
aOffsetThe offset in bytes from the start of the chunk at which to create the heap. If used (and it shouldn't really be!) then it will be rounded up to a multiple of 8, to respect EABI 8 byte alignment requirements.
aGrowByThe number of bytes by which the heap will grow when more memory is required. This will be rounded up to the nearest page size by the allocator. If a value is not explicitly specified, the page size is taken by default.
aMaxLengthThe maximum length in bytes to which the heap can grow. This will be rounded up to the nearest page size by the allocator. If 0 is passed in, the maximum length of the chunk is used.
aAlignFrom Symbian^4 onwards, this value is ignored but EABI 8 byte alignment is guaranteed for all allocations 8 bytes or more in size. 4 byte allocations will be aligned to a 4 byte boundary. Best to pass in zero.
aSingleThreadEFalse if the heap is to be accessed from multiple threads. This will cause internal locks to be created, guaranteeing thread safety.
aModeFlags controlling the heap creation. See RAllocator::TFlags.
Return Value
A pointer to the new heap or NULL if the heap could not be created.
Panic Codes
USER41 if aMaxLength is < aMinLength.
USER55 if aMinLength is negative.
USER56 if aMaxLength is negative.
USER168 if aOffset is negative.

SetupThreadHeap ( TBool, SStdEpocThreadCreateInfo & )

IMPORT_C TIntSetupThreadHeap(TBoolaNotFirst,
SStdEpocThreadCreateInfo &aInfo
)[static]