#ifndef _LOOKASIDELIST_ #define _LOOKASIDELIST_ /****************************************************************************** * LookasideList Functions * ******************************************************************************/ #include "..\Define.h"
#define LAL_MEMORY_BLOCK_SIZE (8) typedef struct _LAL_MEMORY_BLOCK { _LAL_MEMORY_BLOCK* sNext; // 0
DWORD dwMemSize; // 4
CHAR pMemory[1]; // 8
_LAL_MEMORY_BLOCK() { memset(this,0,sizeof(_LAL_MEMORY_BLOCK)); } } LAL_MEMORY_BLOCK, *PLAL_MEMORY_BLOCK;
typedef struct _LAL_BLOCK_HEADER { PLAL_MEMORY_BLOCK pEntry; // 0
WORD wLen; // 4
_LAL_BLOCK_HEADER() { memset(this,0,sizeof(_LAL_BLOCK_HEADER)); } } LAL_BLOCK_HEADER, *PLAL_BLOCK_HEADER;
#define LAL_MEMORY_OBJECT_SIZE (14) typedef struct _LAL_MEMORY_OBJECT { _LAL_MEMORY_OBJECT* pPrev; // 0 for allocated list free
_LAL_MEMORY_OBJECT* pNext; // 4
PVOID pParent; // 8
USHORT usIndex:15; // 12
USHORT usStatus:1; // 0: free 1: allocated
CHAR pMemory[1]; // 14
_LAL_MEMORY_OBJECT() { memset(this,0,sizeof(_LAL_MEMORY_OBJECT)); } } LAL_MEMORY_OBJECT, *PLAL_MEMORY_OBJECT;
typedef struct _LAL_OBJECT_HEADER { PLAL_MEMORY_OBJECT pEntry; // 0
DWORD wLen; // 4
_LAL_OBJECT_HEADER() { memset(this,0,sizeof(_LAL_OBJECT_HEADER)); } } LAL_OBJECT_HEADER, *PLAL_OBJECT_HEADER;
class LOOKASIDE_LIST { private: LAL_BLOCK_HEADER m_sMemoryBlockList; DWORD m_dwObjectSize; WORD m_wMaxObjectNum; WORD m_wDefaultObjectNum; WORD m_wIncreaseObjectNum;
BOOL AddBlock( IN OUT PLAL_BLOCK_HEADER pBlockHeader, IN OUT PLAL_OBJECT_HEADER pObjectHeader, IN CONST DWORD dwObjSize, IN CONST WORD wObjNum); public: enum { PER_BLOCK_OBJ_MAX_NUM = 512, MEM_STATUS_FREE = 0, MEM_STATUS_ALLOCATED = 1, }; LAL_OBJECT_HEADER m_sFreeObjectList; LAL_OBJECT_HEADER m_sAllocatedObjectList; DWORD m_dwRealObjectSize; public: LOOKASIDE_LIST(); ~LOOKASIDE_LIST(); BOOL InitializeLookasideList( IN CONST DWORD dwObjectSize, IN CONST WORD wMaxObjNum, IN CONST WORD wDefaultObjNum, IN CONST WORD wIncreaseObjectNum); BOOL IncreaseBlock(VOID); };
static inline PLAL_MEMORY_OBJECT BodyToHeader ( IN PVOID addr );
PVOID LalAlloc( IN LOOKASIDE_LIST* pLookaside);
VOID LalFree( IN LOOKASIDE_LIST* pLookaside, IN PVOID pMemory);
#endif
|