By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,558 Members | 1,673 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,558 IT Pros & Developers. It's quick & easy.

how to pin object so the gc will not move it in memory ?

P: n/a
im allocating an object that is a wrapper of unmanaged code.

how can i pin that object in memory ,so the gc will not move it.

the reason is some other data members of the object,are sent to unmanaged
code.

hope im clear
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"roni" <ro******@hotmail.com> schrieb:
im allocating an object that is a wrapper of unmanaged code.

how can i pin that object in memory ,so the gc will not move it.

the reason is some other data members of the object,are sent to unmanaged
code.


Take a look at 'GCHandle.Alloc' + 'GCHandleType.Pinned'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #2

P: n/a
>the reason is some other data members of the object,are sent to unmanaged
code.


Note that the runtime will pin arguments you pass to native code for
the duration of the call, so you only have to do it manually (the way
Herfried suggested) if the object must remain pinned after the call
returns.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.