allocates something in one dll and then deallocates it in main exe

D

DDD

I have a piece of codes


// a.dll
void getMyObject(vector<MyClass> &myObject)
{
MyClass a;
...
myObject.push_back(a);
...
MyClass b;
...
myObject.push_back(b);
...
}

void test()
{
....
vector<MyClass> myObject;

// call a function from a.dll
getMyObject(myObject);

// access the myObject
....

return;
}

After runtime come out test() function, there will be an error.
From callback heap view, I see the error comes from vector destruct
function.
Is it because myObject will reallocate object which allocate in a.dll?
 
R

Ron

After runtime come out test() function, there will be an error.
From callback heap view, I see the error comes from vector destruct
function.
Is it because myObject will reallocate object which allocate in a.dll?

This has nothing to do with C++. It has entirely to do with the fact
that each Microsoft Visual Studio runtime library has it's own
allocation
data, so if you have modules linked against different runtime
libraries
you can't deallocate in one that what was allocated in another.

Either (PREFERABLY) keep all your allocations or deallocations
together
*OR* link all your stuff with the same runtime.
 
D

DDD

This has nothing to do with C++.  It has entirely to do with the fact
that each Microsoft Visual Studio runtime library has it's own
allocation
data, so if you have modules linked against different runtime
libraries
you can't deallocate in one that what was allocated in another.

Either (PREFERABLY) keep all your allocations or deallocations
together
*OR* link all your stuff with the same runtime.

Thanks.
 
J

James Kanze

This has nothing to do with C++. It has entirely to do with
the fact that each Microsoft Visual Studio runtime library has
it's own allocation data, so if you have modules linked
against different runtime libraries you can't deallocate in
one that what was allocated in another.

It has nothing to do with C++, because C++ doesn't define DLL's.
But VC++ doesn't have this problem if you link correctly; if
you're using DLL's, you need either -MD or -MDd (normally, the
latter, except in extreme cases).
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top