Re: Returning vectors from a managed dll
- From: Tamas Demjen <tdemjen@xxxxxxxxx>
- Date: Tue, 27 Sep 2005 11:30:20 -0700
www.fruitfruit.com wrote:
Memory allocated by a DLL shall also be freed by itself. If you return a vector from that DLL, you violated above rules.
In fact, you can do that if you ensure that all of the following is true:
* The DLL and the app are compiled with the same compiler and linker settings, with the exact same version of the compiler and linker, and using the exact same STL version
AND
* All modules are linked against the dynamic version of the runtime library
In this case you can allocate memory in a DLL and delete it in the main app, and vice versa, because the memory allocator itself is in the same DLL (the Microsoft runtime library). You must ship the correct Microsoft DLLs with your app as dependencies.
If you can't meet all of those conditions, you're not able to use std::vector in the exported DLL function declarations (whether a return value or an input argument, it doesn't matter).
Also note that returning a vector from a function returns it by value, which means a copy of the vector is created. It's more efficient to pass the vector by reference in one of the input arguments:
void f(vector<int>& output);
Tom .
- References:
- Returning vectors from a managed dll
- From: HealsJnr
- Re: Returning vectors from a managed dll
- From: www.fruitfruit.com
- Returning vectors from a managed dll
- Prev by Date: swap classes that need /clr out to dll
- Next by Date: Re: Finding the application folder !
- Previous by thread: Re: Returning vectors from a managed dll
- Next by thread: Re: vc 7.1 compiler bug
- Index(es):
Relevant Pages
|