On Sun, 31 May 2009 22:41:47 +0300, Walter Bright <newshou...@digitalmars.com> 
wrote:

> Vladimir Panteleev wrote:
>> I don't know why it was decided to mark the contents of void[] as
>> "might have pointers". It makes no sense! Consider:
>
> [...]
>
>> 3) It's very rare in practice that the only pointer to your
>> object (which you still plan to access later) to be stored in a
>> void[]-allocated array!
>
> Rare or common, it still would be a nasty bug lurking to catch someone.  
> The default behavior in D should be to be correct code. Doing  
> potentially unsafe things to improve performance should require extra  
> effort - in this case it would be either using the gc function to mark  
> the memory as not containing pointers, or storing them as ubyte[]  
> instead.

I just realized that by "performance" you might have meant memory leaks. Well, 
sure, if you can say that my programs crashing every few hours due to running 
out of memory is a "performance" problem. I'm sorry to sound bitter, but this 
was the cause of much annoyance for my software's users. It took me to write a 
memory debugger to understand that no matter how much you chase void[]s with 
hasNoPointers, there will always be that one ~ which you overlooked.

As much as I try to look from an objective perspective, I don't see how a 
memory leak (and memory leaks in D usually mean that NO memory is being freed, 
except for small lucky objects not having bogus pointers to them) is a problem 
less significant than an obscure case that involves allocating a void[], 
storing a pointer in it and losing all other references to the object. In fact, 
I just searched the D documentation and I couldn't find a statement saying 
whether void[] are scanned by the GC or not. Enter mr. D-newbie, who wants to 
write his own network/compression/file-copying/etc. library/program and 
stumbles upon void[], the seemingly perfect abstract-binary-data-container type 
for the job... (which is exactly what happened with yours truly).

P.S. Not trying to push my point of view, but just trying to offer some 
perspective from someone who has been bit by this design choice...

-- 
Best regards,
 Vladimir                          mailto:thecybersha...@gmail.com

Reply via email to