Bug 3517 – Allocators proposal

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2009-11-16T15:14:00Z
Last change time
2015-11-03T14:02:03Z
Assigned to
andrei
Creator
k-foley

Attachments

IDFilenameSummaryContent-TypeSize
498allocators_proposal.tar.gzproposed implementation and test/exampleapplication/x-gzip2429

Comments

Comment #0 by k-foley — 2009-11-16T15:14:34Z
Created attachment 498 proposed implementation and test/example I'm proposing a standard way to define and pass around allocators. My primary motivation for proposing this is because I intend to later submit a containers proposal that would then use this allocators structure, where an allocator would be one of the parameters of a container type. But allocators could also be directly usable through some create!(MyType) syntax, as demonstrated in the example. All criticism is welcome :) If there's a better way to submit proposals like this, I want to know about it. The following is test.d from the attachment demonstrating how allocators could be directly usable: --- import std.stdio; import memory.allocators.gc; import memory.allocators.cmallocator; // overload set: choose the gc alias memory.allocators.gc.create create; alias memory.allocators.gc.destroy destroy; struct TestStruct { int a = 42; int b = 23; ~this() { writeln("Struct Destructed"); } } interface TestInterface { bool test(); } class TestClass1 : TestInterface { int a = 99; int b = 1337; string id = ""; this(string rhs) { id = rhs; writeln(id, ".__ctor(string)"); } ~this() { writeln(id, ".__dtor()"); } void print() { writeln("a: ", a, " and b: ", b); } override bool test() { return a < 100; } } class TestClass2 : TestInterface { int a = 23; override bool test() { return a < 20; } } int main() { TestInterface aa = create!(TestClass1)("rawr"); writeln("1: ", aa.test); with ( CMallocator_ClassCreator!TestClass1 ) { auto a = create("CM First"); scope (exit) destroy(a); write("2: "); a.print; } with ( CMallocator_ClassCreator!TestClass2 ) { aa = create(); scope(exit) destroy( cast(TestClass2)aa ); writeln("3: ", (cast(TestClass2)aa).a, " < 20 is ", aa.test); } auto b = create!(TestStruct); auto bb = b; writeln(b.a); bb.a = 92; writeln(b.a); auto c = create!(TestClass2); c.a = 19; writeln("c.a = ", c.a); aa = c; writeln("5: c.a < 20 is ", aa.test); return 0; }
Comment #1 by andrei — 2013-11-15T21:05:11Z
Taking this over.
Comment #2 by andrei — 2015-11-03T14:02:03Z
Finally can mark this as fixed.