Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > garbage collector

Reply
Thread Tools

garbage collector

 
 
Ganesh
Guest
Posts: n/a
 
      09-22-2005

Hi,

How does a garbage collector (in C++), like mark and sweep, work on
heap
allocated arrays? In this case,

1. The only live variable on stack that points to the memory may be the
one that holds the starting address of the array. Or,

2. There could be a stack variable that points to an address that is,
say, in the middle of the array.

How does GC mark the entire array as live in these cases?

Thanks,
Ganesh

 
Reply With Quote
 
 
 
 
Howard
Guest
Posts: n/a
 
      09-22-2005

"Ganesh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>
> Hi,
>
> How does a garbage collector (in C++), like mark and sweep, work on
> heap
> allocated arrays? In this case,
>
> 1. The only live variable on stack that points to the memory may be the
> one that holds the starting address of the array. Or,
>
> 2. There could be a stack variable that points to an address that is,
> say, in the middle of the array.
>
> How does GC mark the entire array as live in these cases?
>


I wasn't aware there *was* any garbage collection in standard C++. If it's
something provided by one of your compilers, then you should probably ask in
a newsgroup or help files for that compiler.

-Howard



 
Reply With Quote
 
 
 
 
acehreli@yahoo.com
Guest
Posts: n/a
 
      09-23-2005
Howard wrote:
> "Ganesh" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...


> > How does a garbage collector (in C++), like mark and sweep, work on
> > heap
> > allocated arrays?

[...]
> I wasn't aware there *was* any garbage collection in standard C++. If it's
> something provided by one of your compilers, then you should probably ask in
> a newsgroup or help files for that compiler.


Good advice, but GC is not necessarily a compiler feature in C or C++.
It can be implemented as a library:

http://www.hpl.hp.com/personal/Hans_Boehm/gc/

That page seems to contain the answers the OP is looking for.

Ali

 
Reply With Quote
 
Ganesh
Guest
Posts: n/a
 
      09-23-2005
I posted my question in this group because:

1. Searching for "Garbage Collection" in groups home, yielded
comp.lang.c++.moderated as the first link. Search for "Garabage
Collector" yeilded 3rd link to the same group. And there were atleast 3
links to this group in the first 10 results. Though, I posted it in
the 'moderated' version, it was not accepted. It is ridiculous, as
there is a disucussion in the same group on a very similar topic and
153 messages have been posted.

2. I used only C++ as my primary programming language. My question had
some assumptions, like having a pointer, which is true in C++ and not
JAVA, and hence I posted it here.

Ganesh

 
Reply With Quote
 
msalters
Guest
Posts: n/a
 
      09-23-2005
Ganesh schreef:

> I posted my question in this group because:
>
> 1. Searching for "Garbage Collection" in groups home, yielded
> comp.lang.c++.moderated as the first link. Search for "Garabage
> Collector" yeilded 3rd link to the same group. And there were atleast 3
> links to this group in the first 10 results. Though, I posted it in
> the 'moderated' version, it was not accepted. It is ridiculous, as
> there is a disucussion in the same group on a very similar topic and
> 153 messages have been posted.


GC isn't always offtopic, as it is possible to combine C++ and GC.
However,
blue-sky discussions about every possible combination wouldn't make
sense.

> 2. I used only C++ as my primary programming language. My question had
> some assumptions, like having a pointer, which is true in C++ and not
> JAVA, and hence I posted it here.


Actually, Java does have pointers, and they're more suited to GC use
than
C++ pointers (no reinterpret_cast<> between int and Object in Java)
There are a lot more languages which use pointers, even if they expose
them only to their internal GC mechanism. That too makes your question
a GC question, an not a C++ question.

Compare: a question about numerical computing is off-topic here, even
if it happened to be implemented in C++. valarray<> would be ontopic.

HTH,
Michiel Salters

 
Reply With Quote
 
Branimir Maksimovic
Guest
Posts: n/a
 
      09-23-2005

"Ganesh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>
> Hi,
>
> How does a garbage collector (in C++), like mark and sweep, work on
> heap
> allocated arrays?


There is no difference between array of objects and single object.
They are all allocated as memory blocks.

In this case,
>
> 1. The only live variable on stack that points to the memory may be the
> one that holds the starting address of the array. Or,
>
> 2. There could be a stack variable that points to an address that is,
> say, in the middle of the array.
>
> How does GC mark the entire array as live in these cases?


GC does not know about arrays. It just tracks pointers to memory area that
is
bound by GC allocated heap.
(I think that you asked about hans boehm gc implementation)
hope this helps.

Greetings, Bane.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JNI problem with Garbage Collector ? bart59 Java 0 06-17-2004 07:34 AM
OutOfMemoryException Error: Garbage Collector doesn't release memory to OS Pyramis ASP .Net 0 01-25-2004 04:37 PM
DVD Verdict reviews: ALIEN: COLLECTOR'S EDITION, ALIEN3: COLLECTOR'S EDITION, and more! DVD Verdict DVD Video 0 12-15-2003 10:05 AM
Garbage collector problem Colt Java 9 11-18-2003 01:15 PM
Garbage Collector Debugging Rob Tillie ASP .Net 11 08-18-2003 10:39 PM



Advertisments