On Tue, 07 Jul 2015 12:36:09 +0000, Rikki Cattermole wrote:

> I'm not aware of much docs regarding these sort of tricks. But I believe
> it was Adam who originally discovered this little trick.
> Atleast I'm pretty sure he is how I learnt about it. On D.learn as well.

i bet this trick was planned from the moment of introduction of slices in 
D.

yet there is something that makes it dangerous: user is free to change 
".length" of the "slice wrapper". and as GC doesn't manage the memory 
slite is pointing to, it will copy slice contents. the program definitely 
will not crash, but if copied data had some pointers to that copied data 
(sometimes C program does this)... besides, one cannot use ".ptr" to `free
()` memory anymore.

so while there is nothing wrong in creating slices from pointers, 
programmer should be aware of some potential pitfalls.

Attachment: signature.asc
Description: PGP signature

Reply via email to