On Mon, 01 Jun 2009 00:53:02 +0400, BCS <n...@anon.com> wrote: > Hello Vladimir, > >> I just went through a ~15000-line project and replaced most >> occurrences of void[]. Now the project is an ugly mess of void[], >> ubyte[] and casts, but at least it doesn't leak memory like crazy any >> more. >> I don't know why it was decided to mark the contents of void[] as >> "might have pointers". It makes no sense! Consider: >> 2) Despite that void[] is "typeless", you can still operate on it - >> namely, slice and concatenate them. Pass a void[] to a network send() >> function - how much did you send? Half the buffer? No problem, slice >> it away and store the rest - and no casts. >> 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! Remember, the properties of memory regions are >> determined when the memory is allocated, so casting an array of >> structures to a void[] will not lose you that reference. You'd need to >> move your pointer to a void[]-array (which you need to allocate >> explicitly or, for example, concatenating your reference to the >> void[]), then drop the reference to your original structure, for this >> to happen. >> > > I think the idea is that void[] is the most general data type; it can be > anything, including pointers. > Also for a real world use case where void[]=mightHavePointers is valid, > consider a system that reads blocks of data structures from a file and > then does in place substation from file references to memory references. > You can't allocate buffers of the correct type because you may not even > know what that is until you have already loaded the data. >
In this case you should *explicitly* mark that void[] array as "mightHavePointers".