[Scummvm-cvs-logs] SF.net SVN: scummvm:[45402] scummvm/trunk/engines/tinsel

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon Oct 26 11:41:28 CET 2009


Revision: 45402
          http://scummvm.svn.sourceforge.net/scummvm/?rev=45402&view=rev
Author:   fingolfin
Date:     2009-10-26 10:41:28 +0000 (Mon, 26 Oct 2009)

Log Message:
-----------
TINSEL: Remove dead stuff from memory managment code, doxygenify some comments

Modified Paths:
--------------
    scummvm/trunk/engines/tinsel/handle.cpp
    scummvm/trunk/engines/tinsel/heapmem.cpp
    scummvm/trunk/engines/tinsel/heapmem.h

Modified: scummvm/trunk/engines/tinsel/handle.cpp
===================================================================
--- scummvm/trunk/engines/tinsel/handle.cpp	2009-10-26 10:41:11 UTC (rev 45401)
+++ scummvm/trunk/engines/tinsel/handle.cpp	2009-10-26 10:41:28 UTC (rev 45402)
@@ -171,7 +171,7 @@
 		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 @@
 
 		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 @@
 
 		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 @@
 		// 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 @@
 
 	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

Modified: scummvm/trunk/engines/tinsel/heapmem.cpp
===================================================================
--- scummvm/trunk/engines/tinsel/heapmem.cpp	2009-10-26 10:41:11 UTC (rev 45401)
+++ scummvm/trunk/engines/tinsel/heapmem.cpp	2009-10-26 10:41:28 UTC (rev 45402)
@@ -109,18 +109,7 @@
 	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.
  */
 static MEM_NODE *AllocMemNode(void) {
@@ -202,7 +191,7 @@
 
 					// 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 @@
 
 				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 @@
 					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 @@
 }
 
 /**
- * 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 @@
 	// 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 @@
 		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);

Modified: scummvm/trunk/engines/tinsel/heapmem.h
===================================================================
--- scummvm/trunk/engines/tinsel/heapmem.h	2009-10-26 10:41:11 UTC (rev 45401)
+++ scummvm/trunk/engines/tinsel/heapmem.h	2009-10-26 10:41:28 UTC (rev 45402)
@@ -43,20 +43,13 @@
 };
 
 // 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 @@
 
 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 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 @@
 	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
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list