Re: Returning vectors from a managed dll

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • Re: What programming language for Future
    ... usually when apps come with scripts, those scripts are for that version of ... version of the app. ... Which is exactly the same as when the compiler is shipped with the app. ... for the sole reason that they can't rebuild a working dll. ...
    (comp.lang.misc)
  • Re: Firefox and Sound
    ... number of loads that app performed. ... only references to entry points in the dll. ... specified entry points in it can't be found, ... but the download manager said it was only 78.8 MB. ...
    (comp.os.os2.apps)
  • Re: New Delphi roadmap is coming: NO UNICODE PLEASE!
    ... Avoids DLL hell, because it ... The app is deployed and the user is getting an error. ... instances where upgrading .NET broke things that were working. ... Coming from Delphi, this isn't any big deal of course. ...
    (borland.public.delphi.non-technical)
  • Re: What programming language for Future
    ... usually when apps come with scripts, those scripts are for that version ... version of the app. ... Which is exactly the same as when the compiler is shipped with the app. ... for the sole reason that they can't rebuild a working dll. ...
    (comp.lang.misc)
  • Re: How can I get a MFC DLL with NO own CWinApp/AfxGetApp() ?
    ... so I would like not to establish a new one for the DLL ... Microsoft has confused the concept of a CWinApp ... your app and you should not think that it does. ... let alone anything about a CWinApp in MFC. ...
    (microsoft.public.vc.mfc)