Phobos 3 Discussion Notes - 02-01-2024

Atila Neves atila.neves at gmail.com
Mon Feb 12 17:00:01 UTC 2024


On Wednesday, 7 February 2024 at 21:26:51 UTC, jmh530 wrote:
> On Wednesday, 7 February 2024 at 10:10:27 UTC, Atila Neves 
> wrote:
>> [snip]
>>
>> The problem with this approach, as C++ found out, is that 
>> `Vector!(int, MyAlloc)` is a different type from `Vector!(int, 
>> YourAlloc)`. The way I got around that is by defaulting to a 
>> global allocator. This has its drawbacks as well of course, 
>> because now everything is a virtual call.
>
> If you need to allocate or deallocate, then it's useful to 
> treat them as separate types. Otherwise it's not.

     alias MyVec = Vector(MyType, Mallocator);
     void fun(MyVec vec) {
          // just before the curly brace, the elements and storage 
for them get deallocated.
     }



More information about the Digitalmars-d mailing list