diff options
| author | Max Horn | 2009-10-26 10:41:28 +0000 |
|---|---|---|
| committer | Max Horn | 2009-10-26 10:41:28 +0000 |
| commit | e963dfbd172dd461bf246a09552eca5c07cb52b1 (patch) | |
| tree | 323d64ace6784853518835ec3c9a5518389b84b2 /engines/tinsel | |
| parent | bbe0b81aff36cc188d598ba3d66cc2521e14c0f2 (diff) | |
| download | scummvm-rg350-e963dfbd172dd461bf246a09552eca5c07cb52b1.tar.gz scummvm-rg350-e963dfbd172dd461bf246a09552eca5c07cb52b1.tar.bz2 scummvm-rg350-e963dfbd172dd461bf246a09552eca5c07cb52b1.zip | |
TINSEL: Remove dead stuff from memory managment code, doxygenify some comments
svn-id: r45402
Diffstat (limited to 'engines/tinsel')
| -rw-r--r-- | engines/tinsel/handle.cpp | 12 | ||||
| -rw-r--r-- | engines/tinsel/heapmem.cpp | 79 | ||||
| -rw-r--r-- | engines/tinsel/heapmem.h | 28 |
3 files changed, 12 insertions, 107 deletions
diff --git a/engines/tinsel/handle.cpp b/engines/tinsel/handle.cpp index b1d4e608df..87989a6edb 100644 --- a/engines/tinsel/handle.cpp +++ b/engines/tinsel/handle.cpp @@ -171,7 +171,7 @@ void SetupHandleTable(void) { else { // allocate a discarded memory node for other files pH->_node = MemoryAlloc( - DWM_MOVEABLE | DWM_DISCARDABLE | DWM_NOALLOC, + DWM_DISCARDABLE | DWM_NOALLOC, pH->filesize & FSIZE_MASK); pH->_ptr = NULL; @@ -383,8 +383,7 @@ byte *LockMem(SCNHANDLE offset) { if (pH->_node->pBaseAddr == NULL) // must have been discarded - reallocate the memory - MemoryReAlloc(pH->_node, cdTopHandle-cdBaseHandle, - DWM_MOVEABLE | DWM_DISCARDABLE); + MemoryReAlloc(pH->_node, cdTopHandle - cdBaseHandle, DWM_DISCARDABLE); if (pH->_node->pBaseAddr == NULL) error("Out of memory"); @@ -406,8 +405,7 @@ byte *LockMem(SCNHANDLE offset) { if (pH->_node->pBaseAddr == NULL) // must have been discarded - reallocate the memory - MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK, - DWM_MOVEABLE | DWM_DISCARDABLE); + MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK, DWM_DISCARDABLE); if (pH->_node->pBaseAddr == NULL) error("Out of memory"); @@ -451,7 +449,7 @@ void LockScene(SCNHANDLE offset) { // WORKAROUND: The original didn't include the DWM_LOCKED flag. It's being // included because the method is 'LockScene' so it's presumed that the // point of this was that the scene's memory block be locked - MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK, DWM_MOVEABLE | DWM_LOCKED); + MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK, DWM_LOCKED); #ifdef DEBUG bLockedScene = true; #endif @@ -474,7 +472,7 @@ void UnlockScene(SCNHANDLE offset) { if ((pH->filesize & fPreload) == 0) { // change the flags for the node - MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK, DWM_MOVEABLE | DWM_DISCARDABLE); + MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK, DWM_DISCARDABLE); #ifdef DEBUG bLockedScene = false; #endif diff --git a/engines/tinsel/heapmem.cpp b/engines/tinsel/heapmem.cpp index b358b945e0..aaf2405c8a 100644 --- a/engines/tinsel/heapmem.cpp +++ b/engines/tinsel/heapmem.cpp @@ -109,17 +109,6 @@ void MemoryInit(void) { heapSentinel.flags = DWM_LOCKED | DWM_SENTINEL; } - -#ifdef DEBUG -/** - * Shows the maximum number of mnodes used at once. - */ - -void MemoryStats(void) { - printf("%i mnodes of %i used.\n", maxNodes, NUM_MNODES); -} -#endif - /** * Allocate a mnode from the free list. */ @@ -202,7 +191,7 @@ bool HeapCompact(long size, bool bDiscard) { // leave the loop break; - } else if ((pPrev->flags & (DWM_MOVEABLE | DWM_LOCKED | DWM_DISCARDED)) == DWM_MOVEABLE + } else if ((pPrev->flags & (DWM_LOCKED | DWM_DISCARDED)) == 0 && pCur->flags == 0) { // a free block after a moveable block - swap them @@ -297,12 +286,6 @@ MEM_NODE *MemoryAlloc(int flags, long size) { if (pNode->size == size) { // an exact fit - - // check for zeroing the block - if (flags & DWM_ZEROINIT) - memset(pNode->pBaseAddr, 0, size); - - // return the node return pNode; } else { // allocate a node for the remainder of the free block @@ -325,16 +308,12 @@ MEM_NODE *MemoryAlloc(int flags, long size) { pNode->pPrev->pNext = pTemp; pNode->pPrev = pTemp; - // check for zeroing the block - if (flags & DWM_ZEROINIT) - memset(pNode->pBaseAddr, 0, size); - return pNode; } } } // compact the heap if we get to here - bCompacted = HeapCompact(size, (flags & DWM_NOCOMPACT) ? false : true); + bCompacted = HeapCompact(size, true); } // not allocated a block if we get to here @@ -423,51 +402,6 @@ void MemoryDiscard(MEM_NODE *pMemNode) { } /** - * Frees the specified memory object and invalidates its node. - * @param pMemNode Node of the memory object - */ -void MemoryFree(MEM_NODE *pMemNode) { - MEM_NODE *pPrev, *pNext; - - // validate mnode pointer - assert(pMemNode >= mnodeList && pMemNode <= mnodeList + NUM_MNODES - 1); - - // get pointer to the next mnode - pNext = pMemNode->pNext; - - // get pointer to the previous mnode - pPrev = pMemNode->pPrev; - - if (pPrev->flags == 0) { - // there is a previous free mnode - pPrev->size += pMemNode->size; - - // unlink this mnode - pPrev->pNext = pNext; // previous to next - pNext->pPrev = pPrev; // next to previous - - // free this mnode - FreeMemNode(pMemNode); - - pMemNode = pPrev; - } - if (pNext->flags == 0) { - // the next mnode is free - pMemNode->size += pNext->size; - - // flag as a free block - pMemNode->flags = 0; - - // unlink the next mnode - pMemNode->pNext = pNext->pNext; - pNext->pNext->pPrev = pMemNode; - - // free the next mnode - FreeMemNode(pNext); - } -} - -/** * Locks a memory object and returns a pointer to the first byte * of the objects memory block. * @param pMemNode Node of the memory object @@ -502,19 +436,12 @@ MEM_NODE *MemoryReAlloc(MEM_NODE *pMemNode, long size, int flags) { // validate mnode pointer assert(pMemNode >= mnodeList && pMemNode <= mnodeList + NUM_MNODES - 1); - // validate the flags - // must be moveable - assert(flags & DWM_MOVEABLE); - // align the size to machine boundary requirements size = (size + sizeof(void *) - 1) & ~(sizeof(void *) - 1); // validate the size assert(size); - // make sure we want the node on the same heap - assert((flags & (DWM_SOUND | DWM_GRAPHIC)) == (pMemNode->flags & (DWM_SOUND | DWM_GRAPHIC))); - if (size == pMemNode->size) { // must be just a change in flags @@ -526,7 +453,7 @@ MEM_NODE *MemoryReAlloc(MEM_NODE *pMemNode, long size, int flags) { pMemNode->pPrev->pNext = pMemNode->pNext; // allocate a new node - pNew = MemoryAlloc(flags | DWM_MOVEABLE, size); + pNew = MemoryAlloc(flags, size); // make sure memory allocated assert(pNew != NULL); diff --git a/engines/tinsel/heapmem.h b/engines/tinsel/heapmem.h index 2bea20f231..4d508edbba 100644 --- a/engines/tinsel/heapmem.h +++ b/engines/tinsel/heapmem.h @@ -43,20 +43,13 @@ struct MEM_NODE { }; // allocation flags for the MemoryAlloc function -#define DWM_MOVEABLE 0x0002 ///< allocates movable memory #define DWM_DISCARDABLE 0x0004 ///< allocates discardable memory #define DWM_NOALLOC 0x0008 ///< when used with discardable memory - allocates a discarded block -#define DWM_NOCOMPACT 0x0010 ///< does not discard memory to satisfy the allocation request -#define DWM_ZEROINIT 0x0020 ///< initialises memory contents to zero -#define DWM_SOUND 0x0040 ///< allocate from the sound pool -#define DWM_GRAPHIC 0x0080 ///< allocate from the graphics pool - -// return value from the MemoryFlags function -#define DWM_DISCARDED 0x0100 // the objects memory block has been discarded // internal allocation flags -#define DWM_LOCKED 0x0200 // the objects memory block is locked -#define DWM_SENTINEL 0x0400 // the objects memory block is a sentinel +#define DWM_DISCARDED 0x0100 ///< the objects memory block has been discarded +#define DWM_LOCKED 0x0200 ///< the objects memory block is locked +#define DWM_SENTINEL 0x0400 ///< the objects memory block is a sentinel /*----------------------------------------------------------------------*\ @@ -65,11 +58,7 @@ struct MEM_NODE { void MemoryInit(void); // initialises the memory manager -#ifdef DEBUG -void MemoryStats(void); // Shows the maximum number of mnodes used at once -#endif - -// allocates a non-fixed block with the specified number of bytes from the heap +// allocates a movable block with the specified number of bytes from the heap MEM_NODE *MemoryAlloc( int flags, // allocation attributes long size); // number of bytes to allocate @@ -80,12 +69,6 @@ void *MemoryAllocFixed(long size); void MemoryDiscard( // discards the specified memory object MEM_NODE *pMemNode); // node of the memory object -int MemoryFlags( // returns information about the specified memory object - MEM_NODE *pMemNode); // node of the memory object - -void MemoryFree( // frees the specified memory object and invalidates its node - MEM_NODE *pMemNode); // node of the memory object - MEM_NODE *MemoryHandle( // Retrieves the mnode associated with the specified pointer to a memory object void *pMem); // address of memory object @@ -97,9 +80,6 @@ MEM_NODE *MemoryReAlloc( // changes the size or attributes of a specified memory long size, // new size of block int flags); // how to reallocate the object -long MemorySize( // returns the size, in bytes, of the specified memory object - MEM_NODE *pMemNode); // node of the memory object - void MemoryUnlock( // unlocks a memory object MEM_NODE *pMemNode); // node of the memory object |
