Re: To Pin or Copy memory?
- From: "G Himangi" <info@xxxxxxxxxx>
- Date: Sat, 5 May 2007 16:04:35 +0530
I believe that depends on the number of times the win32 API is being called.
If it is called just a couple of times, then it wont matter at all what
method is used. If it is however used in a loop or otherwise called a
ignorant number of times, then the choice will matter. It also depends on
the size of the data that is to be passed.
---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
rapidly in .Net
---------
"obiwanjacobi" <obiwanjacobi@xxxxxxxxxxx> wrote in message
news:1178104412.537061.252340@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
I'm trying to decide what is the best way to pass a data structure to
a P/Invoked Win32 function.
As far as I can tell there are two options:
1) Use the Marshal class to allocate native memory an copy the data
into it.
2) Use the GCHandle to pin a managed object that has the exact same
layout.
I know that pinning will hinder the GC's efficiency. Allocating native
memory will increase the 'memory pressure' for the GC but not
interfere with its collection strategies and it requires additional
copy instructions to move the data.
So whats the best choice when both performance and memory management
efficiency are important?
Thanx
Marc Jacobi
.
- Follow-Ups:
- Re: To Pin or Copy memory?
- From: obiwanjacobi
- Re: To Pin or Copy memory?
- References:
- To Pin or Copy memory?
- From: obiwanjacobi
- To Pin or Copy memory?
- Prev by Date: Re: Outlook 2007 automation with VS.NET 2005
- Next by Date: 'Invalid handle' error when calling CreateProcessAsUser
- Previous by thread: Re: To Pin or Copy memory?
- Next by thread: Re: To Pin or Copy memory?
- Index(es):
Relevant Pages
|