Is this a good pattern for allocation?
JS
js.mdnq at gmail.com
Sun Aug 4 18:47:22 PDT 2013
Trying to avoid GC dependence on my objects.
interface Alloc(T)
{
T New(A...)(A args);
//final T Factory(A...)(T, A args) { return new T(args); }
}
class A(T) : Alloc!(A!(T))
{
....
static A!T New()
{
return new A!T(); // Use GC for now
// Factor(A!T);
}
}
(I'm not sure why the static New satisfies the interface but dmd
doesn't complain)
Using New instead of new removes a dependence step. If I could
get the factory to work, then it could be used by New to help
setup the object, the factory just allocating the object while
New setting it up properly.
Anyways, is this a bad or good way and how can I call Factory to
get a new object? (I know that ther is .init and other stuff that
can be used by Factor/New. I'm just trying to get the skeleton to
compile and make sure there are not going to be major issues in
the future.
More information about the Digitalmars-d-learn
mailing list