Hi all
In C++/CLI, is there a way to free an array allocated from an
unmanaged dll ? In my managed code, I call a function from that dll
which returns me an array of bytes. But how can I free it ?
Thanks 8 1751
>In C++/CLI, is there a way to free an array allocated from an
>unmanaged dll ?
Only if you know (and have the exact same access to) the memory
manager that allocated it.
>In my managed code, I call a function from that dll which returns me an array of bytes. But how can I free it ?
More details and a short example are probably needed before a
definitive answer can be given.
Dave
On 9 jan, 13:26, David Lowndes <Dav...@example.invalidwrote:
More details and a short example are probably needed before a
definitive answer can be given.
in my unmnaged dll :
int *function()
{
int *a = new int[16];
// fill array, etc...
return a;
}
in my managed dll (C++/CLI):
tab = function();
// misc. operations with tab...
delete[] tab; // error
so, in my managed dll, once I finish to play with tab, I have to free
it, but my complier don't like my delete[]
LeXave wrote:
On 9 jan, 13:26, David Lowndes <Dav...@example.invalidwrote:
>More details and a short example are probably needed before a definitive answer can be given.
in my unmnaged dll :
int *function()
{
int *a = new int[16];
// fill array, etc...
return a;
}
in my managed dll (C++/CLI):
tab = function();
// misc. operations with tab...
delete[] tab; // error
so, in my managed dll, once I finish to play with tab, I have to free
it, but my complier don't like my delete[]
LeXave:
Are you sure that both DLL's are using the same version of the CRT?
But, personally, I do not like this mixed new/delete across DLL
boundaries. What happens if you export another function from your
unmanaged DLL:
void free_function(int* a)
{
delete [] a;
}
and call it from your managed DLL?
--
David Wilkinson
Visual C++ MVP
On 9 jan, 15:07, David Wilkinson <no-re...@effisols.comwrote:
Dave,
What happens if you export another function from your
unmanaged DLL:
It would certainly be the best solution, but the problem is that I
don't own the source of that dll, so I can't modify it :(
Both dll use the same version of the CRT (compiled both with VS 2005)
>Both dll use the same version of the CRT (compiled both with VS 2005)
You can't mix debug & release components (they have different heaps),
and they both have to be built to use the DLL CRT option.
Dave
>
It would certainly be the best solution, but the problem is that I
don't own the source of that dll, so I can't modify it :(
Then a better solution would be to create your own C++/CLI wrapper around the DLL to put a managed front face to it. For example,
you could copy the int[] array to a managed array, then delete[] the unmanaged array before returned the managed array.
"Brian Muth" <bm***@mvps.orgwrote in message
news:ey**************@TK2MSFTNGP06.phx.gbl...
It would certainly be the best solution, but the problem is that I don't own the source of that dll, so I can't modify it :(
Then a better solution would be to create your own C++/CLI wrapper around
the DLL to put a managed front face to it. For example, you could copy the
int[] array to a managed array, then delete[] the unmanaged array before
returned the managed array.
As I understand the original post, that's exactly what's not working.
Perhaps the original DLL has statically linked the CRT and returned pointers
allocated by that static CRT, in which case there is no way to safely free
the memory.
>
As I understand the original post, that's exactly what's not working.
Perhaps the original DLL has statically linked the CRT and returned pointers
allocated by that static CRT, in which case there is no way to safely free
the memory.
Aaggh. That makes sense. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bryan |
last post by:
I have a multi-threaded C# console application that uses WMI
(System.Management namespace) to make RPC calls to several servers (600+ )
and returns ScheduledJobs. The section of my code that...
|
by: Barry Anderberg |
last post by:
I'm using a tool by Sci-Tech called the .NET Memory Profiler.
We have a massive .NET/C# application here and it has been exhibiting
memory leak behavior for some time. Attempting to remedy the...
|
by: Rachel Suddeth |
last post by:
What is the difference between a managed/unmanaged resource, and how do you
tell which is which? I'm trying to understand how to write some Dispose()
methods, and we are supposed to put code that...
|
by: zhphust |
last post by:
I want to convert a object of a managed class to a unmanaged structure
that has the same member with that managed class. Can anybody tell me
how i can do it?
Thanks in advance.
--
zhphust...
|
by: Sparhawk |
last post by:
Hi,
my company is going to migrate a large VC++ application to .NET to
make use of Windows Forms (the old class library is not updated any
more). We are not planning to migrate the rest of the...
| |
by: Steve |
last post by:
I have former VC++ 6.0 application which was ported to .NET.
Now we continue to develop this app under VS.NET. The app
now contains both managed and unmanaged classes.
Now I have a problem with...
|
by: Maxwell |
last post by:
Hello,
Newbie question here for disposing of unmanaged resources in MC++.NET.
I have a managed VS.NET 2003 MC++ wrapper class that wraps a unmanaged
C++ dll. What I am trying to figure out is...
|
by: thomson |
last post by:
Hi All,
Connecting to SQL Server we say its an Un Managed
connection Can any one tell me whether this statement
objConnection = new
System.Data.OleDb.OleDbConnection(strConnectionString);
...
|
by: Stephen Walch |
last post by:
Our application environment consists of three basic layers:
1. Third-party unmanaged DLLs that were written before the CLR was invented
and maintain a significant amount of information (including...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |