Exemplo n.º 1
0
      void
      allocateChunk ()
      {
        chunks.push_back (new Chunk); // requires c++17 new with alignment

        for (Storage& storage : chunks.back ())
          {
            FreeListNode *node = reinterpret_cast<FreeListNode*> (&storage);
            new (node) FreeListNode;
            freeList.push_front (*node);
          }
      }
Exemplo n.º 2
0
 void
 free (void* t)
 {
   FreeListNode *node = reinterpret_cast<FreeListNode*> (t);
   new (node) FreeListNode;
   freeList.push_front (*node);
   ++freeCount;
   assert(([this]()->bool
     { // check we have no double-frees
       std::set<FreeListNode*> s;
       for(auto &n: freeList) s.insert(&n);
       return s.size() == freeList.size();
     }) ());
 }