You mena something like this?
----
use(Mallocator) {
int[] arr;
arr ~= 42;
}
----
Or did I understand you wrong?
It depends on how Mallocator is related to integer array (which
again boils down to allocator design). If it is appropriate,
then yes.
Whats about the virtual property idea, that every array has
internal an allocator? Wouldn't it be easier to implement such
a thing?
Please provide example.
Something like that:
http://forum.dlang.org/thread/[email protected]?page=3#post-pfoxyfzyjxqcqwnvgnpi:40forum.dlang.org
Every array has an internal allocator property which can be reset:
----
int[] arr;
arr.allocator = Mallocator;
----
or
----
int[] arr;
arr.useAllocator(Mallocator);
----
But maybe a design without some alias notation would be more
preferable:
----
{
ScopeAllocator m;
int[] arr;
arr.useAllocator(m);
arr ~= 42; /// Use m.allocate
} /// end of scope: ScopeAllocator collects all remaining memory.
----
And:
----
int[] arr;
assert(arr is null);
{
ScopeAllocator m;
arr.useAllocator(m);
arr ~= 42; /// Use m.allocate
} /// end of scope: ScopeAllocator collects all remaining memory.
assert(arr is null);
----