Exemplo n.º 1
0
/* initialize the memory management module */
void initMemoryManager()
{
    int i;

# ifdef obtalloc
    objectTable = obtalloc(ObjectTableMax, sizeof(struct objectStruct));
    if (! objectTable)
        sysError("cannot allocate","object table");
# endif

    /* set all the free list pointers to zero */
    for (i = 0; i < FREELISTMAX; i++)
        objectFreeList[i] = nilobj;

    /* set all the reference counts to zero */
    for (i = 0; i < ObjectTableMax; i++)
    {
        objectTable[i].referenceCount = 0;
        objectTable[i].size = 0;
    }

    /* make up the initial free lists */
    setFreeLists();

# ifndef mBlockAlloc
    /* force an allocation on first object assignment */
    currentMemoryPosition = MemoryBlockSize + 1;
# endif

    /* object at location 0 is the nil object, so give it nonzero ref */
    objectTable[0].referenceCount = 1;
    objectTable[0].size = 0;
}
Exemplo n.º 2
0
MemoryManager::MemoryManager(size_t initialSize, size_t growCount) : noGC(false), growAmount(growCount)
{
    objectTable.resize(initialSize);

    /* set all the reference counts to zero */
    for(TObjectTableIterator i = objectTable.begin(), iend = objectTable.end(); i != iend; ++i)
    {
        i->referenceCount = 0; 
        i->size = 0; 
    }

    /* make up the initial free lists */
    setFreeLists();

    /* object at location 0 is the nil object, so give it nonzero ref */
    objectTable[0].referenceCount = 1; objectTable[0].size = 0;
}
Exemplo n.º 3
0
void MemoryManager::imageRead(FILE* fp)
{   
  long i, size;

  fr(fp, (char *) &symbols, sizeof(object));
  i = 0;

  while(fr(fp, (char *) &dummyObject, sizeof(dummyObject))) 
  {
    i = dummyObject.di;

    if ((i < 0) || (i >= objectTable.size()))
    {
        // Grow enough, plus a bit.
        growObjectStore(i - objectTable.size() + 500);
    }
    objectTable[i]._class = dummyObject.cl;
    if ((objectTable[i]._class < 0) || 
        ((objectTable[i]._class) >= objectTable.size())) 
    {
        // Grow enough, plus a bit.
        growObjectStore(objectTable[i]._class - objectTable.size() + 500);
    }
    objectTable[i].size = size = dummyObject.ds;
    if (size < 0) size = ((- size) + 1) / 2;
    if (size != 0) 
    {
      objectTable[i].memory = mBlockAlloc((int) size);
      fr(fp, (char *) objectTable[i].memory,
          sizeof(object) * (int) size);
    }
    else
      objectTable[i].memory = (object *) 0;

    objectTable[i].referenceCount = 666;
  }
  setFreeLists();
}