C Library using Hans Boehm GC & Managed C++

L

Lloyd Dupont

I am using an OpenSource library I have wrapped in Managed C++.
There is no way I can do without it :-(.

Due to on going problem with this library (which I cannot debug as it is not
in a language supported by VS.NET and as GDB is pitifully inadequate) I plan
to compile this library with Boehm GC support.

I wonder if everything will work allright?

basically what I have looks like:
======================

// == The native library interface (which I will recompile with Boehm GC)

// create and destory pointers
struct TheObject { /* ... */ };
struct TheObject * createObject(char *);
void Destroy(struct* theObj); // presumably with GC enabled does nothing

// use it
struct void AMethod(struct TheObject* char* amethod, int param);

// == my MC++ wrapper
public ref class MyNClass
{
public:
MyClass()
{
pointer = createObject("TheObject");
}
~MyClass()
{
Destroy(pointer);
pointer = NULL;
}
AMethod(int p)
{
aMethod(pointer, "amethod", p);
}


private:
struct TheObject * pointer;
}

=====================

Will this all works gracefully?
comments, tips, links or similar experience?
 
C

Carl Daniel [VC++ MVP]

Lloyd said:
I am using an OpenSource library I have wrapped in Managed C++.
There is no way I can do without it :-(.

Due to on going problem with this library (which I cannot debug as it
is not in a language supported by VS.NET and as GDB is pitifully
inadequate) I plan to compile this library with Boehm GC support.

I wonder if everything will work allright?

Who knows :) It really depends on the library. That said, there's no
reason that the CLR and the Boehm GC can't co-exist since they'll each be
managing their own separate heap.

-cd
 
L

Lloyd Dupont

The problem
this object:
public ref class MyNClass
{
public:
MyClass()
{
pointer = createObject("TheObject");
}
~MyClass()
{
Destroy(pointer);
pointer = NULL;
}
AMethod(int p)
{
aMethod(pointer, "amethod", p);
}


private:
struct TheObject * pointer;
}

is in the managed heap.
hence I'm afraid that Boehm GC won't be able to find the "pointer" pointer
and might free it while it is still in use!

well, I'm going to find out....
 
C

Carl Daniel [VC++ MVP]

Lloyd Dupont said:
The problem
this object:
public ref class MyNClass
{
public:
MyClass()
{
pointer = createObject("TheObject");
}
~MyClass()
{
Destroy(pointer);
pointer = NULL;
}
AMethod(int p)
{
aMethod(pointer, "amethod", p);
}


private:
struct TheObject * pointer;
}

is in the managed heap.
hence I'm afraid that Boehm GC won't be able to find the "pointer" pointer
and might free it while it is still in use!

well, I'm going to find out....

Hmmm.... good point! I hadn't looked at the code you posted closely enough
to appreciate that wrinkle.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top