Beispiel #1
0
SVector* SVSet::create(int idxmax)
{
   DLPSV* ps;

   if (list.last())
   {
      ps = list.last();
      removeLast(ps->max() - ps->size());
      ps->set_max( ps->size() );
   }

   if (idxmax < 0)
   {
      ensureMem(2);
      idxmax = memMax() - memSize() - 1;
   }
   else
      ensureMem(idxmax + 1);

   ensurePSVec(1);

   assert( memMax() >= memSize() + idxmax + 1 );

   ps = set.create();
   list.append(ps);
   /// resize the dataarray
   SVSetBase::reSize(memSize() + idxmax + 1);

   ps->setMem(idxmax + 1, &last() - idxmax);
   return ps;
}
Beispiel #2
0
void SVSet::ensureMem(int n)
{
   if (memSize() + n > memMax())
   {
      int newMax = int( memFactor * memMax() );
      if ( memSize() + n > newMax )
         newMax  = memSize() + n;
      memRemax( newMax );
   }
}
Beispiel #3
0
void SVSet::xtend(SVector& svec, int newmax)
{
   if (svec.max() < newmax)
   {
      if (possiblyUnusedMem * memFactor > memSize())
         memPack(); 

      assert(has(&svec));
      DLPSV* ps = static_cast<DLPSV*>( & svec );

      if (ps == list.last())
      {
         int sz = ps->size();
         ensureMem (newmax - ps->max() + 1);
         insert(memSize(), newmax - ps->max());
         ps->setMem (newmax + 1, ps->mem());
         ps->set_size( sz );
      }
      else
      {
         ensureMem(newmax + 1);
         SVector newps(newmax + 1, &last() + 1);
         int sz = ps->size();
         insert(memSize(), newmax + 1);
         newps = svec;

         if (ps != list.first())
         {
            SVector* prev = ps->prev();
            int prevsz = prev->size();
            prev->setMem (prev->max()
                           + ps->max() + 2, prev->mem());
            prev->set_size(prevsz);
            
            possiblyUnusedMem += ps->max();
         }
         list.remove(ps);
         list.append(ps);

         ps->setMem(newmax + 1, newps.mem());
         ps->set_size(sz);
      }
   }
}
Beispiel #4
0
Tuple::Tuple(size_t length, Tag tag)
{
    if (tag != Tag::tuple && tag != Tag::string)
        throw RunError("non-tuple tag in tuple constructor");

    auto numBytes = memSize(length);
    auto ptr = vm.alloc(numBytes);

    // Set the internal tuple pointer
    tuple = Value(ptr, tag);

    // Set the tuple length
    *(uint32_t*)ptr = length;
}
Beispiel #5
0
int main () {

   srand(time(NULL));

   int handle[3];
   int *myInts[30];
   int bytesRequested[30];
   int totalBytesRequested;
   
   long n_bytes = 1048576; // 1 MB
   
   int parm2[10];
   parm2[0] = 16;
   parm2[1] = 32;
   parm2[2] = 64;
   parm2[3] = 128;
   parm2[4] = 12432;
   parm2[5] = 1223;
   parm2[6] = 0;
   
   handle[0] = meminit (n_bytes, BUDDY_FLAG, 4, parm2);  
   handle[1] = meminit (n_bytes, SLAB_FLAG, 8, parm2);
   handle[2] = meminit (n_bytes, FREELIST_FLAG, 0, parm2);
   
   int handleCount;
   for (handleCount = 0; handleCount < 3; handleCount++) {
      totalBytesRequested = 0;
      if (handle[handleCount] < 0)
         printf ("%s: %s %d %s\n", "ERROR", "handle", handleCount, "did not initialize");
      int counter;
      for (counter = 0; counter < 30; counter++) {
         int randBytes = sizeof(char)*((rand()%99)+1); //1 - 100 bytes
         myInts[counter] = (int*)memalloc (handle[handleCount], randBytes);
         bytesRequested[counter] = randBytes;
         totalBytesRequested += randBytes;
      }
      // Free half
      for (counter = 0; counter < 30; counter+=2) {
         memfree(myInts[counter]);
         totalBytesRequested -= bytesRequested[counter];
         bytesRequested[counter] = 0;
      }
      // Reallocate
      for (counter = 0; counter < 30; counter+=2) {
         int randBytes = sizeof(char)*((rand()%99)+1); //1 - 100 bytes
         myInts[counter] = (int*)memalloc (handle[handleCount], randBytes);
         bytesRequested[counter] = randBytes;
         totalBytesRequested += randBytes;
      }
      int memoryUsed = memUsed(handle[handleCount]);
      printf("Allocator %d:\n", handleCount);
      printf("Total bytes: %d\n", memSize(handle[handleCount]));
      printf("Total bytes requested: %d\n", totalBytesRequested);
      printf("Total bytes used: %d\n", memoryUsed);
      printf("Total waste: %f%%\n", (1- (float)totalBytesRequested/memoryUsed)*100);
      if (handleCount == 0) handle[0] = handle[1];
      else if (handleCount == 1) handle[0] = handle[2];
   }
   
   printf("Tester complete.\n");
}