473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

garbage collector


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

Sep 22 '05 #1
5 1604

"Ganesh" <ga*****@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro 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

Sep 22 '05 #2
Howard wrote:
"Ganesh" <ga*****@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro 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

Sep 23 '05 #3
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

Sep 23 '05 #4
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

Sep 23 '05 #5

"Ganesh" <ga*****@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro 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.
Sep 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob | last post by:
Are there any known applications out there used to test the performance of the .NET garbage collector over a long period of time? Basically I need an application that creates objects, uses them, and...
4
by: Pedro Miguel Carvalho | last post by:
Greetings. I'm creating a project that as a intricate relation between object kind of like a set where each object in the set can be connect to a subset of object of the set and objects not in...
10
by: pachanga | last post by:
The Hans-Boehm garbage collector can be successfully used with C and C++, but not yet a standard for C++.. Is there talks about Garbage Collector to become in the C++ standard?
5
by: Ben | last post by:
Could someone please verify if what I am doing as follow is corrected: 1. when dealing with custom class objects: ..... public myObject as myClass myObject as New myClass .......here I am...
13
by: Mingnan G. | last post by:
Hello everyone. I have written a garbage collector for standard C++ application. It has following main features. 1) Deterministic Finalization Providing deterministic finalization, the system...
28
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
142
by: jacob navia | last post by:
Abstract -------- Garbage collection is a method of managing memory by using a "collector" library. Periodically, or triggered by an allocation request, the collector looks for unused memory...
8
by: Paul.Lee.1971 | last post by:
Hi everyone, A program that I'm helping to code seems to slow down drastically during initialisation, and looking at the profiling graph, it seems to be the garbage collector thats slowing things...
56
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application =...
46
by: Carlo Milanesi | last post by:
Hello, traditionally, in C++, dynamically allocated memory has been managed explicitly by calling "delete" in the application code. Now, in addition to the standard library strings, containers,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.