My question is more precisely; what kind of allocations do the
allocator template argument of e.g.
vector<> handle? It seems that they deal with allocation of elements in the vector, not with allocation of the vector internals, such as the vector's internal array.
My point is that I wanted to use STL with GC_malloc only on data which does not use non-memory resources (this typically excludes
vector<ofstream> for example). In that case, the only useful resource is memory, and I want it to be handled by Boehm's GC.
Recall that Boehm's GC is a conservative collector which tracks by marking all reachable memory zones (reachable from the stack and global data, by conservatively handling every word as a potential pointer) and frees (essentially thru
GC_free) all memory zones which is not live (i.e. not marked as such in the previous marking step). This can happen at any call to
GC_malloc etc..).
And indeed, for simplicity, I assumed that openrator
::new called the system
malloc. This is true on Linux but is an implementation detail handled by Boehm's GC.
So if my vector (instanciated template) used only
GC_malloc internally (ie
new(GC) but not
::new) I would be happy. I won't have to call delete, and the memory resource is managed by Boehm's collector. Trust me, it works well. Of course, Boehm's GC does not call any C++ destructor (because it does not call any delete C++ operator, only GC_free!), but that it ok for my use: it only reclaim automatically memory which is not live anymore (for a conservative approximation of live).
However, if there is no way of instanciating the
vector<> or
map<> template such as every internal allocation (inside STL code for vector) is using GC_malloc (or
new(GC) which wraps it) then I cannot use C++.
Thanks for reading.
--
Basile Starynkevitch
http://starynkevitch.net/Basile/