diff options
author | Max Horn | 2009-05-18 12:35:18 +0000 |
---|---|---|
committer | Max Horn | 2009-05-18 12:35:18 +0000 |
commit | 62876a5ad5bd03c227188dd8bf297fb4e2096b6e (patch) | |
tree | de00104eda4e2a6eb7088e71c5add44795017931 /engines | |
parent | 5170acd00c9ca7cdeebc72ac172292e9dc3b69fe (diff) | |
download | scummvm-rg350-62876a5ad5bd03c227188dd8bf297fb4e2096b6e.tar.gz scummvm-rg350-62876a5ad5bd03c227188dd8bf297fb4e2096b6e.tar.bz2 scummvm-rg350-62876a5ad5bd03c227188dd8bf297fb4e2096b6e.zip |
SCI: Changed SegManager to not pre-allocate _heap entries (leave the memory management to Common::Array)
svn-id: r40686
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 66 |
1 files changed, 29 insertions, 37 deletions
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index e034515aae..b9ec613fb8 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -52,38 +52,13 @@ namespace Sci { #define INVALID_SCRIPT_ID -1 -int SegManager::findFreeId(int *id) { - bool was_added = false; - int retval = 0; - - while (!was_added) { - retval = id_seg_map->checkKey(reserved_id, true, &was_added); - *id = reserved_id--; - if (reserved_id < -1000000) - reserved_id = -10; - // Make sure we don't underflow - } - - return retval; -} - -MemObject *SegManager::allocNonscriptSegment(MemObjectType type, SegmentId *segid) { - // Allocates a non-script segment - int id; - - *segid = findFreeId(&id); - return memObjAllocate(*segid, id, type); -} - SegManager::SegManager(bool sci1_1) { id_seg_map = new IntMapper(); reserved_id = INVALID_SCRIPT_ID; - id_seg_map->checkKey(reserved_id, true); // reserve 0 for seg_id + id_seg_map->checkKey(reserved_id, true); // reserve entry 0 for INVALID_SCRIPT_ID reserved_id--; // reserved_id runs in the reversed direction to make sure no one will use it. - _heap.resize(DEFAULT_SCRIPTS); - for (uint i = 0; i < _heap.size(); ++i) - _heap[i] = 0; + _heap.push_back(0); Clones_seg_id = 0; Lists_seg_id = 0; @@ -105,6 +80,29 @@ SegManager::~SegManager() { delete id_seg_map; } +int SegManager::findFreeId(int *id) { + bool was_added = false; + int retval = 0; + + while (!was_added) { + retval = id_seg_map->checkKey(reserved_id, true, &was_added); + *id = reserved_id--; + if (reserved_id < -1000000) + reserved_id = -10; + // Make sure we don't underflow + } + + return retval; +} + +MemObject *SegManager::allocNonscriptSegment(MemObjectType type, SegmentId *segid) { + // Allocates a non-script segment + int id; + + *segid = findFreeId(&id); + return memObjAllocate(*segid, id, type); +} + // allocate a memory for script from heap // Parameters: (EngineState *) s: The state to operate on // (int) script_nr: The script number to load @@ -319,14 +317,8 @@ MemObject *SegManager::memObjAllocate(SegmentId segid, int hash_id, MemObjectTyp } if (segid >= (int)_heap.size()) { - const int oldSize = _heap.size(); - if (segid >= oldSize * 2) { - sciprintf("SegManager: hash_map error or others??"); - return NULL; - } - _heap.resize(oldSize * 2); - for (int i = oldSize; i < oldSize * 2; ++i) - _heap[i] = 0; + assert(segid == (int)_heap.size()); + _heap.push_back(0); } mem->_segmgrId = hash_id; @@ -1062,11 +1054,11 @@ unsigned char *SegManager::allocDynmem(int size, const char *descr, reg_t *addr) } const char *SegManager::getDescription(reg_t addr) { - MemObject *mobj = _heap[addr.segment]; - if (addr.segment >= _heap.size()) return ""; + MemObject *mobj = _heap[addr.segment]; + switch (mobj->getType()) { case MEM_OBJ_DYNMEM: return (*(DynMem *)mobj)._description; |