Karl Heinz Buchegger wrote:[color=blue]
> Rick wrote:
>[color=green]
>>Chris Dams wrote:
>>[color=darkred]
>>>Well, to begin with, why do you need garbarge collection for things like
>>>ints and doubles anyway? Even java does not garbage collect these types
>>>normally.[/color]
>>
>>Because something like:
>>
>>int *a = new int[10000];
>>
>>will cause a memory leak if I don't collect it once a is modified to:
>>
>>int b = 99;
>>a = &b;
>>
>>Java's primitive types are stored on the stack *but* something like:
>>
>>int[] a = new int[1000];
>>
>>in java would store the array on the heap, which *is* garbage collected
>>eventually.
>>
>>This is why I have a garbage collector to do the dirty work for me.[/color]
>
>
> C++ is programmed differently then Java.
> In C++ you would write:
>
> int a[1000];
>
> and be done with it. No need to allocate dynamically.
> If you must allocate dynamically, you can always use:
>
> #include <vector>
>
> ...
> int some_number;
> ...
> std::vector< int > a( some_number );
>
> which allocates a dynamic array (the vector) of a specific size and
> does all the dirty work of managing the memory for you (a vector
> can even grow as necessary).
>
> Please try to learn C++ and the way things are done in C++ instead
> of applying Java techniques (and wasting time by rebuilding them)
> to C++. In C++ there is no need for a GC, the RAII idiom is
> usually the way to go and works well. But if you still feel the need
> for a GC, then check out
>
>
http://www.hpl.hp.com/personal/Hans_Boehm/gc/
>[/color]
Yes I know all about GCs and I've seen this website. I'm only interested
in building one because I'm interested in learning how to. I dont even
think I'll use it with my programs but writing such things always makes
you learn new stuff which I'm eager to.
Rick