Freelists and clear/emplace

F i L witte2008 at gmail.com
Sat Jun 16 12:34:55 PDT 2012


On Saturday, 16 June 2012 at 01:14:06 UTC, d coder wrote:
> Greetings
>
> Is emplace/clear  mechanism mature enough to be used to create 
> freelists?
>
> I looked but found very scanty documentation on emplace/clear 
> on dlang.org.
>
> Regards
> - Puneet

I did performance tests awhile ago and emplace() was virtually 
identical to raw assignment. I'm not sure how familiar you are 
with D, but personally I prefer D's mixin templates for freelists:

   mixin template Pool(T) { // FreeList
     static T poolHead;
     public T poolNext;

     static auto create() { ... }
     static void delete() { ... }
   }


   class MyClass {
     mixin Pool!MyClass;
   }

   struct MyStruct {
     mixin Pool!MyStruct;
   }


   void main() {
     auto mc = MyClass.create();
     auto ms = MyStruct.create();

     ...

     mc.delete();
     ms.delete();
   }


More information about the Digitalmars-d mailing list