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();
  }

Reply via email to