DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Tue, 17 Jul 2007 05:49:42 -0700,    posted on: microsoft.public.dotnet.framework.interop        back       

Thread Index
  1    m...
          2    Micky Duncan


How to free the memory allocated in unmanged code from managed code?   
Hi,

I am using a COM component which provides a function like
GetBitmapData(out BYTE* pData, out long *pLen), in which it allocates
the memory using "new" and returns the pointer and length of memory
block.

i am calling this functon in C# in following way...
int pImageBuffer = 0;
int len = 0;

m_COMAdapter.GetBitmapData(ref pImageBuffer, out len);
IntPtr ImageData = new IntPtr(pImageBuffer);
//I use IntPtr
//Now I need to free up the memory allocated by GetBitmapData()

I am not sure how i can free up the memory here?

I tried Marshal.FreeCoTaskMem(ImageData), but its not helping and i am
sure if it is the correct way...

thx,
m...
Date:Tue, 17 Jul 2007 05:49:42 -0700   Author:  

Re: How to free the memory allocated in unmanged code from managed code?   
Hi,
If your COM object allocates the data then it should be the one that frees 
it too. Add a method called FreeBitmapData() or something on the COM object.

This is actually a good practice from the days of c++ DLLs where memory is 
allocated and shared amonst the DLL's clients.  Clients don't free the data 
but rather the one who allocated it in the first place - the DLL

Cheers,
Micky

"m..."  wrote in message 
news:1184676582.852590.122670@x35g2000prf.googlegroups.com...

> Hi,
>
> I am using a COM component which provides a function like
> GetBitmapData(out BYTE* pData, out long *pLen), in which it allocates
> the memory using "new" and returns the pointer and length of memory
> block.
>
> i am calling this functon in C# in following way...
> int pImageBuffer = 0;
> int len = 0;
>
> m_COMAdapter.GetBitmapData(ref pImageBuffer, out len);
> IntPtr ImageData = new IntPtr(pImageBuffer);
> //I use IntPtr
> //Now I need to free up the memory allocated by GetBitmapData()
>
> I am not sure how i can free up the memory here?
>
> I tried Marshal.FreeCoTaskMem(ImageData), but its not helping and i am
> sure if it is the correct way...
>
> thx,
> m...
> 
Date:Mon, 30 Jul 2007 10:50:08 +0800   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us