[Gc] Re: Boehm GC problem

Ivan Maidanski ivmai at mail.ru
Sat Dec 28 13:20:48 PST 2013


 Hi Vadim,

It is better to send questions to the ML (gc at linux.hpl.com). Probably someone on the list knows the answer.

I have tried your sample but it worked for me (on cygwin), the output:
1000
1

1001
1

Just for reference, I used the recent BDWGC snapshot and following commands to build the sample:
gcc -I include -c extra/gc.c
g++ -I include test_app.cpp gc.o 

[Translated] Fri, 27 Dec 2013, 16:51 +04:00 from Vadim <grutargo at gmail.com>:
>Hi.
>I have an issue with Boehm GC, probably you could help me.
>I found the solution  https://www.drdobbs.com/the-boehm-collector-for-c-and-c/184401632?pgno=6 how to use the collector for the std types but it does not work for me.
>
>The code:
>
>#include "app.h" I replaced it to:
#include <iostream>
#include <stdlib.h>
#include "gc_cpp.h"

>
>using namespace std;
>
>long allocated = 0;
>
>template<class Super>
>class Boehmable : public Super, public virtual gc_cleanup
>{
>public:
>Boehmable() : Super(), gc_cleanup() { allocated++; }
>virtual ~Boehmable() { allocated--; }
>};
>
>class MyClass
>{
>public:
>MyClass() {};
>~MyClass() {};
>};
>
>int main(int argc, char **argv)
>{
>for (int i = 0; i < 1000; i++)
>{
>new Boehmable<MyClass>();
>}
>
>cout << allocated << endl;    // 1000
>GC_gcollect();
>cout << allocated << endl << endl;  // 1 - It works 
>
>for (int i = 0; i < 1000; i++)
>{
>new Boehmable<string>();
>}
>
>cout << allocated << endl;    // 1001
>GC_gcollect();
>cout << allocated << endl << endl;  // 1001 - Does not work!
>
>system("pause");
>
>return 0;
>}
>
>Does not work for list, vector, etc. types neither.
Regards,
Ivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://napali.hpl.hp.com/pipermail/gc/attachments/20131229/bc3ba0a9/attachment.htm


More information about the Gc mailing list