question about the garbage collector
Saaa
empty at needmail.com
Sun Mar 4 18:44:28 PST 2007
And dynamic arrays, right?
(rant below)
I had some really strange problems with the gc.
In my main loop I had to read in .png files quite alot (using SDL_Image) and
place them on a SDL_Surface.
I had this problem of sometimes iso the png a black screen would appear.
(always the same place(changing the actual picture didn't change a thing))
I traced the problem down to this:
array.length=1800000;
Without this line (the array wasn't even in use) there were no black
screens.
My best solution still > first line in main > disable(); > no problems and a
big array :D
I'll report my bug when I'm sure it is (making the program minimal somehow
:)
Somehow setting the array length enables the gc and somehow the gc redirects
the pointer, I think... more info later :)
>
> D's garbage collector only applies to things that are allocated via the
> 'new' keyword in D code*. C typically uses malloc, which the D garbage
> collector can't even see, much less mess with. If you use malloc and
> free from D code, then what you allocate using malloc won't be garbage
> collected, either.
>
> As for initialising it, I think this is what they're saying:
>
> +) If you write your own WinMain function, you need to handle
> initialising and shutting down the D runtime stuff like the GC, unit
> tests, module ctors, etc.
>
> +) If your program begins with a main function, on the other hand, you
> don't need to worry about doing the setup manually, since D will have
> handled it for you. You just need to figure out a way to get the
> information that's usually passed to WinMain in some other manner.
>
> Hope this helps.
>
> -- Daniel
>
> * Of course, this doesn't apply if you happen to override a particular
> class' new and delete methods, but you hopefully won't be doing *that*
> unless you already know how the GC works :P
>
> --
> Unlike Knuth, I have neither proven or tried the above; it may not even
> make sense.
>
> v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
> i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d-learn
mailing list