This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc-in-cxx: Garbage Collecting STL Containers


Chris Jefferson wrote:
Could someone point me towards what is necessary to add STL containers
to the garbage collector?

One big problem with garbage collecting in C++ is the need to run
destructors. If the (I believe very reasonable) decision is made to
require that running destructors is not necessary for garbage
collected types, then my experience is doing gc is very easy, and for
garbage collection it's easy to just look at the internal members
which all behave "sensibly".

Stripping away all the C++isms, and assuming that we use the default
allocator which uses malloc, then a std::vector is just a struct

struct vector
{
  T* begin;
  T* finish;
  T* end_of_storage;
};

Where we increment finish whenever we add something to the vector,
until finish = end_of_storage, at which point new memory is allocated,
the data is copied across, and then the old memory is freed. I can't
think of any other (or any simpler) way to construct a variable sized
container, in either C or C++.

Other containers are similar.

I fully agree on that point. To summarize: most of the classes in the gcc-in-cxx should have no destructor at all, or a trivial destructor which only destroys the data inside.


However, I am not sure this applies to std::string etc..

In addition, this raise several questions:

Does complex static data (i.e. statically allocated instances of complex classes) is allowed in gcc-in-cxx?

Do we intend to have a wide forest of classes in gcc-in-cxx? I would prefer a tree of classes (with only single inheritance) sharing a common root class.

At last, C++ permits interesting ways of writing garbage collectors, because it can help to make easier the boxing of GC-ed values on the stack.

Regards.

--
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]