Classes |
struct | LSA_SMALL_ALLOC_BLOCKSET |
Protected Types |
typedef struct
lsa::CSmallAllocator::LSA_SMALL_ALLOC_BLOCKSET * | LPLSA_SMALL_ALLOC_BLOCKSET |
typedef struct
lsa::CSmallAllocator::LSA_SMALL_ALLOC_BLOCKSET | LPCLSA_SMALL_ALLOC_BLOCKSET |
Protected Member Functions |
LSE_CALL | CSmallAllocator (LSVOID *_pvAddress, LSUINT32 _ui32Total256Blocks) |
LSVOID LSE_CALL | Init (LSVOID *_pvAddress, LSUINT32 _ui32Total256Blocks) |
LSVOID *LSE_CALL | Alloc (LSA_SIZE _sSize, LSUINT32 _ui32Align=(1UL<< 4UL)) |
LSBOOL LSE_CALL | Free (LSVOID *_pvAddr) |
LSVOID *LSE_CALL | ReAlloc (LSVOID *_pvAddr, LSA_SIZE _sSize, LSA_SIZE &_sOldSize) |
LSBOOL LSE_CALL | IsEmpty () const |
LSVOID LSE_CALL | Trash () |
LSBOOL LSE_CALL | HaveAddress (const LSVOID *_pvAddr) const |
Static Protected Member Functions |
static LSA_SIZE LSE_CALL | GetWorkingSetSizeByNumberOf256Blocks (LSUINT32 _ui32Total256Blocks, const LSVOID *_pvAddress=NULL, LSA_SMALL_ALLOC_BLOCKSET *_psabBlocks=NULL) |
static LSA_SIZE LSE_CALL | GetFullAllocatorSizeWithNumberOf256Blocks (LSVOID *_pvAddress, LSUINT32 _ui32Total256Blocks) |
static LSUINT32 LSE_CALL | GetElementsFromBits (LSUINT32 _ui32Bits) |
static LSUINT32 LSE_CALL | GetByteAndBitFromBit (const LSUINT32 &_ui32Bit, LSUINT32 &_ui32ReturnBit) |
static LSUINT32 LSE_CALL | Find0Bit (LSA_SIZE _sValue) |
static LSE_INLINE LSUINTPTR
LSE_CALL | GetBlockOffset (LSUINT32 _ui32SetIndex, LSUINT32 _ui32BlockIndex) |
Protected Attributes |
CSmallAllocator * | m_psaNext |
LSA_SMALL_ALLOC_BLOCKSET | m_pui8BlockStarts [(256/(1<< 4UL))] |
LSA_SIZE | m_sLow |
LSA_SIZE | m_sHi |
Friends |
class | CStdAllocator |
Provide a more efficient way of handling allocations of small sizes.
Class CSmallAllocator Description: Similar to CStdAllocatorHeap in purpose, but this manages only small allocations (256 bytes and below). In CStdAllocatorHeap, every allocation, no matter how small, causes 16 extra bytes to be allocated as overhead for record keeping. Because the allocations can be of variable sizes, values must be stored to indicate the size of each block. Blocks can also be variable distances apart so linked-list pointers must be inserted. In debug mode, 32 additional bytes are allocated for each allocation instead of 16. The CSmallAllocator handles small allocations separately to avoid all this needless overhead and not only improves allocation/deallocation speed but also improves RAM efficiency. This is done by organizing the blocks into fixed-sized rows. The sizes of the blocks are known already so we do not need to store this information. The blocks are stacked and are fixed in size so we know where each block is. A simple bit array tells us if a block is allocated or not. Deallocation is exceptionally fast since we only need to take the address of the block minus the start of the blocks to get a bit index, then switch that bit to 0. Searching for free blocks is also fast because a search over the bit array can check 32 blocks at once. When an array of 32 bits is found where not all bits are set to 1, a binary bit scan finds a free block.
static LSA_SIZE LSE_CALL lsa::CSmallAllocator::GetWorkingSetSizeByNumberOf256Blocks |
( |
LSUINT32 |
_ui32Total256Blocks, |
|
|
const LSVOID * |
_pvAddress = NULL , |
|
|
LSA_SMALL_ALLOC_BLOCKSET * |
_psabBlocks = NULL |
|
) |
| [static, protected] |
Given the number of 256-sized blocks desired, determine how much RAM will be needed to allow us to work with a set where each smaller block set consumes the same or less RAM as the 256-sized block set. In other words, if 16 256-sized blocks are given, the total size for that set will be 4,096 bytes (not including the 16 bits for record-keeping). Then, 256 16-byte blocks will be created, 128 32-byte blocks, 85 48-byte blocks, etc. The sum of all of these blocks, including the sizes of the bits needed for record keeping, is returned.
- Parameters:
-
_ui32Total256Blocks | Total number of 256-byte-sized blocks to consider as a guideline for the rest of the working set. |
_pvAddress | If not NULL, this is the address where the working set should be applied. |
_psabBlocks | If not NULL, the pointers in the given LSA_SMALL_ALLOC_BLOCKSET objects are set while the size is being calculated. |
- Returns:
- Total RAM consumed for the whole working set assuming a starting address aligned on a 16-byte boundary.