On 23.12.2011 21:51, bearophile wrote:
Mr. Anonymous:
http://dlang.org/memory.html#uninitializedarrays
It's said here ^ that:
"The uninitialized data that is on the stack will get scanned by the
garbage collector looking for any references to allocated memory."
With the given example of: byte[1024] buffer = void;
So does the GC really scan this byte array? Or (sounds more logical to
me) does it scan only reference types?
If the latter is true, I think the example should use some kind of a
pointer array. Also, in this case, I can't see why "Uninitialized data
can be a source of bugs and trouble, even when used correctly."?
If the former is true, then, well, I'll ask more questions.
>
The current D GC is not precise, so I think the current DMD+GC scan this array.
Future better compilers/runtimes probably will be able to avoid it (with a
shadow stack the gives precise typing information at runtime, used by a precise
GC).
Well, if that's really so, then it's not 100% reliable.
e.g. you generate an array of random numbers, and one of them appears to
be an address of an allocated array. This array won't free even if not
used anymore.