Array Slices and Interior Pointers

Alex Rønne Petersen alex at lycus.org
Wed Dec 12 06:40:40 PST 2012


On 12-12-2012 09:30, Dmitry Olshansky wrote:
> 12/12/2012 12:59 AM, Alex Rønne Petersen пишет:
> [snip]
>>>
>>> I'd mention that the most of idiomatic D code is agnostic with respect
>>> to the origin of slice. The major reason to use slices is to avoid
>>> allocations and thus the allocation scheme is not important up to the
>>> point of explicit copy.
>>>
>>> And at that point e.g. Phobos plays it safe and does everything that has
>>> to copy or incrementally build via GC. And it gets bashed for it every
>>> once in a while. To put simply it's because there is no concept of
>>> allocators in idiomatic D code _yet_.
>>>
>>> And separating slices and allocation mechanism behind them is the key of
>>> usability of slices as they stand. If we add stuff that makes them 50%
>>> more bulky and helps only a certain scheme of GC memory allocation we
>>> are screwed.
>>
>> Then our current slice design is broken.
>>
>> int[] arr;
>> arr.length = 1024; // guess where this memory comes from?
>>
> Nice one ;)
> Guess this point was destroyed.
>

Just to clarify: I'm not saying you're wrong. I think the fact that that 
particular slice feature is tied to the GC is actually a pretty bad thing.

-- 
Alex Rønne Petersen
alex at lycus.org
http://lycus.org


More information about the Digitalmars-d mailing list