aboutsummaryrefslogtreecommitdiff
path: root/engines/tinsel/heapmem.cpp
diff options
context:
space:
mode:
authorMax Horn2009-10-26 10:41:11 +0000
committerMax Horn2009-10-26 10:41:11 +0000
commitbbe0b81aff36cc188d598ba3d66cc2521e14c0f2 (patch)
tree0e80d17016153e5cc604c9da6b6ce9b63db54dbd /engines/tinsel/heapmem.cpp
parent9065dca09aeb046d2e4b76a3edf82b9b8360a7e4 (diff)
downloadscummvm-rg350-bbe0b81aff36cc188d598ba3d66cc2521e14c0f2.tar.gz
scummvm-rg350-bbe0b81aff36cc188d598ba3d66cc2521e14c0f2.tar.bz2
scummvm-rg350-bbe0b81aff36cc188d598ba3d66cc2521e14c0f2.zip
TINSEL: Remove DWM_FIXED and add new MemoryAllocFixed() function
svn-id: r45401
Diffstat (limited to 'engines/tinsel/heapmem.cpp')
-rw-r--r--engines/tinsel/heapmem.cpp89
1 files changed, 35 insertions, 54 deletions
diff --git a/engines/tinsel/heapmem.cpp b/engines/tinsel/heapmem.cpp
index 8a5d351381..b358b945e0 100644
--- a/engines/tinsel/heapmem.cpp
+++ b/engines/tinsel/heapmem.cpp
@@ -279,11 +279,6 @@ MEM_NODE *MemoryAlloc(int flags, long size) {
MEM_NODE *pNode;
bool bCompacted = true; // set when heap has been compacted
- // compact the heap if we are allocating fixed memory
- if (flags & DWM_FIXED) {
- HeapCompact(MAX_INT, false);
- }
-
#ifdef SCUMM_NEED_ALIGNMENT
const int alignPadding = sizeof(void*) - 1;
size = (size + alignPadding) & ~alignPadding; //round up to nearest multiple of sizeof(void*), this ensures the addresses that are returned are alignment-safe.
@@ -307,12 +302,8 @@ MEM_NODE *MemoryAlloc(int flags, long size) {
if (flags & DWM_ZEROINIT)
memset(pNode->pBaseAddr, 0, size);
- if (flags & DWM_FIXED)
- // lock the memory
- return (MEM_NODE *)MemoryLock(pNode);
- else
- // just return the node
- return pNode;
+ // return the node
+ return pNode;
} else {
// allocate a node for the remainder of the free block
MEM_NODE *pTemp = AllocMemNode();
@@ -326,34 +317,19 @@ MEM_NODE *MemoryAlloc(int flags, long size) {
// set size of node
pNode->size = size;
- if (flags & DWM_FIXED) {
- // place the free node after pNode
- pTemp->pBaseAddr = pNode->pBaseAddr + size;
- pTemp->pNext = pNode->pNext;
- pTemp->pPrev = pNode;
- pNode->pNext->pPrev = pTemp;
- pNode->pNext = pTemp;
-
- // check for zeroing the block
- if (flags & DWM_ZEROINIT)
- memset(pNode->pBaseAddr, 0, size);
-
- return (MEM_NODE *)MemoryLock(pNode);
- } else {
- // place the free node before pNode
- pTemp->pBaseAddr = pNode->pBaseAddr;
- pNode->pBaseAddr += freeSize;
- pTemp->pNext = pNode;
- pTemp->pPrev = pNode->pPrev;
- pNode->pPrev->pNext = pTemp;
- pNode->pPrev = pTemp;
-
- // check for zeroing the block
- if (flags & DWM_ZEROINIT)
- memset(pNode->pBaseAddr, 0, size);
-
- return pNode;
- }
+ // place the free node before pNode
+ pTemp->pBaseAddr = pNode->pBaseAddr;
+ pNode->pBaseAddr += freeSize;
+ pTemp->pNext = pNode;
+ pTemp->pPrev = pNode->pPrev;
+ pNode->pPrev->pNext = pTemp;
+ pNode->pPrev = pTemp;
+
+ // check for zeroing the block
+ if (flags & DWM_ZEROINIT)
+ memset(pNode->pBaseAddr, 0, size);
+
+ return pNode;
}
}
}
@@ -383,6 +359,21 @@ MEM_NODE *MemoryAlloc(int flags, long size) {
return NULL;
}
+
+void *MemoryAllocFixed(long size) {
+ // Allocate a fixed block of data. For now, we simply malloc it!
+ // TODO: We really should keep a list of the allocated pointers,
+ // so that we can discard them later on, when the engine quits.
+
+#ifdef SCUMM_NEED_ALIGNMENT
+ const int alignPadding = sizeof(void*) - 1;
+ size = (size + alignPadding) & ~alignPadding; //round up to nearest multiple of sizeof(void*), this ensures the addresses that are returned are alignment-safe.
+#endif
+
+ return malloc(size);
+}
+
+
/**
* Discards the specified memory object.
* @param pMemNode Node of the memory object
@@ -512,14 +503,8 @@ MEM_NODE *MemoryReAlloc(MEM_NODE *pMemNode, long size, int flags) {
assert(pMemNode >= mnodeList && pMemNode <= mnodeList + NUM_MNODES - 1);
// validate the flags
- // cannot be fixed and moveable
- assert((flags & (DWM_FIXED | DWM_MOVEABLE)) != (DWM_FIXED | DWM_MOVEABLE));
-
- // cannot be fixed and discardable
- assert((flags & (DWM_FIXED | DWM_DISCARDABLE)) != (DWM_FIXED | DWM_DISCARDABLE));
-
- // must be fixed or moveable
- assert(flags & (DWM_FIXED | DWM_MOVEABLE));
+ // must be moveable
+ assert(flags & DWM_MOVEABLE);
// align the size to machine boundary requirements
size = (size + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
@@ -541,7 +526,7 @@ MEM_NODE *MemoryReAlloc(MEM_NODE *pMemNode, long size, int flags) {
pMemNode->pPrev->pNext = pMemNode->pNext;
// allocate a new node
- pNew = MemoryAlloc((flags & ~DWM_FIXED) | DWM_MOVEABLE, size);
+ pNew = MemoryAlloc(flags | DWM_MOVEABLE, size);
// make sure memory allocated
assert(pNew != NULL);
@@ -560,12 +545,8 @@ MEM_NODE *MemoryReAlloc(MEM_NODE *pMemNode, long size, int flags) {
FreeMemNode(pNew);
}
- if (flags & DWM_FIXED)
- // lock the memory
- return (MEM_NODE *)MemoryLock(pMemNode);
- else
- // just return the node
- return pMemNode;
+ // return the node
+ return pMemNode;
}
/**