473,513 Members | 3,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning vectors from a managed dll

Hi all,

Just wondering if there is any way to return a vector from a mixed mode
dll? I understand that it is quite easy to pass by reference to achieve
the same end, but i'd like to know if it is possible to return a
vector.

Cheers,

Nov 17 '05 #1
2 1180
you should not do that even if possible considering memory management
problem:
Memory allocated by a DLL shall also be freed by itself.
If you return a vector from that DLL, you violated above rules.
"HealsJnr" <he******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all,

Just wondering if there is any way to return a vector from a mixed mode
dll? I understand that it is quite easy to pass by reference to achieve
the same end, but i'd like to know if it is possible to return a
vector.

Cheers,

Nov 17 '05 #2
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
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
11894
by: mjm | last post by:
Folks, Stroustrup indicates that returning by value can be faster than returning by reference but gives no details as to the size of the returned object up to which this holds. My question is...
18
2116
by: cppaddict | last post by:
Hi, Is it considered bad form to have the subscript operator return a const reference variable? If not, what is the proper way to do it? My question was prompted by the code below, my...
12
3257
by: Olumide | last post by:
I'm studying Nigel Chapman's Late Night Guide to C++ which I think is an absolutely fantastic book; however on page 175 (topic: operator overlaoding), there the following code snippet: inline...
8
1767
by: slurper | last post by:
if i have a vector and assign another vector to a vector variable like this: vector<int> c, k; c.push_back(1), c.push_back(2); k.push_back(3), k.push_back(4); c = k; does this work?? if...
25
2899
by: Victor Bazarov | last post by:
In the project I'm maintaining I've seen two distinct techniques used for returning an object from a function. One is AType function(AType const& arg) { AType retval(arg); // or default...
9
1526
by: Brian Victor | last post by:
I have a situation where I have a vector<gcroot<ManagedWrapperClass*> > whose contents I need to pass to an unmanaged function. Is there a way to pin all the pointers in the vector for that...
5
14295
by: Robert Fitzpatrick | last post by:
Can someone point me to some more information or perhaps show an example of returning a recordset from a plpgsql function. I'd like to send an argument or arguments to the function, do some queries...
26
2768
by: cdg | last post by:
Could anyone correct any mistakes in this example program. I am just trying to return an array back to "main" to be printed out. And I am not sure how a "pointer to an array" is returned to the...
23
2902
by: pauldepstein | last post by:
Below is posted from a link for Stanford students in computer science. QUOTE BEGINS HERE Because of the risk of misuse, some experts recommend never returning a reference from a function or...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.