std.allocator ready for some abuse

Namespace rswhite4 at googlemail.com
Fri Oct 25 01:13:20 PDT 2013


>> Are you saying that this code:
>> ----
>> with (setAllocator!Mallocator) {
>>    int[] arr;
>>    arr ~= 42; [1]
>> }
>> ----
>> use the mallocator for [1]? So no GC memory is needed?
>>
>> Another examaple:
>> ----
>> with (setAllocator!ScopeAllocator) {
>>    int[] arr;
>>    arr ~= 42; [1]
>> }
>> ----
>> Did [1] use ScopeAllocator for memory allocation? And is the 
>> memory of arr automatically collected at the end of the scope 
>> with ScopeAllocator?
>
> This is impossible because with() has already another meaning. 
> However nothing stops from inventing another name for this. 
> Compiler can insert calls to druntime as well to other context 
> dependent functions. After allocator design is defined we can 
> move on to step 2, implementing this idea.

You mena something like this?
----
use(Mallocator) {
     int[] arr;
     arr ~= 42;
}
----
Or did I understand you wrong?

Whats about the virtual property idea, that every array has 
internal an allocator? Wouldn't it be easier to implement such a 
thing?


More information about the Digitalmars-d mailing list