473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

question about pinning pointers

J
I understand how to pin pointers as they are declared, but for some
reason, I can'f figure out the syntax for predaclaring a pointer and
then pinning in afterward like you would if you wanted to embed an
unmanaged object: Assumingthat pAudioU has alread been defined
as the appriate type of pointer,

Instead of
pAudioU = new __pin AudioDriver_U; // syntax error

it seems necessary to take the extra step of creating an intermediate
pointer and then assigning that:

AudioDriver_U __pin *U = new AudioDriver_U;
pAudioU = U;

Am I overlooking some syntactical subtlety?
Nov 17 '05 #1
3 879
Am I overlooking some syntactical subtlety?


In metadata, the pinning nature of the pointer is recorded as a
modifier on the local variable type. You can see this if you view the
code with ILDASM. So basicly you need a __pin local variable for
pinning.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2
J wrote:
I understand how to pin pointers as they are declared, but for some
reason, I can'f figure out the syntax for predaclaring a pointer and
then pinning in afterward like you would if you wanted to embed an
unmanaged object: Assumingthat pAudioU has alread been defined
as the appriate type of pointer,

Instead of
pAudioU = new __pin AudioDriver_U; // syntax error

it seems necessary to take the extra step of creating an intermediate
pointer and then assigning that:

AudioDriver_U __pin *U = new AudioDriver_U;
pAudioU = U;

Am I overlooking some syntactical subtlety?

If I understood the question, you can do:
SomeClass *p= __gc new SomeClass;

// ...

SomeClass __pin *pinp= p;

// ... Do stuff with pinned object
//Unpin object
pinp=0;


--
Ioannis Vranos
Nov 17 '05 #3
J
On Sat, 05 Feb 2005 12:16:32 +0100, Mattias Sjögren
<ma********************@mvps.org> wrote:
Am I overlooking some syntactical subtlety?


In metadata, the pinning nature of the pointer is recorded as a
modifier on the local variable type. You can see this if you view the
code with ILDASM. So basicly you need a __pin local variable for
pinning.


so in regard to this:

pAudioU = new __pin AudioDriver_U; // syntax error

OK, that just won't compile...

vs this:
AudioDriver_U __pin *U = new AudioDriver_U;
pAudioU = U;

Did you mean that the latter is a necessessity... or it won't function
as planned? Just want to be clear about it.

The counterintuitive thing: It would seem that you can't easily keep
a permanent pinned pointer to a permanently embedded unmanaged object.
Yet that is exactly what you want to do for embedded unmanaged DLLs
and such, right?

How on earth did you figure this out? The MSDN never seems quite
clear on this stuff. I'd like to avoid P-Invoke if possible. Is
there a definitive reference on how to manage C++ wrappers?
Nov 17 '05 #4

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

Similar topics

3
by: J | last post by:
I understand how to pin pointers as they are declared, but for some reason, I can'f figure out the syntax for predaclaring a pointer and then pinning in afterward like you would if you wanted to...
1
by: demofo | last post by:
Does the pinning pointer safe?since the Read function will change the ppBuffer points to unmanaged C++ heap,how does the dot net runtime knows they will not move the allocated memory (pointed by...
4
by: Chris | last post by:
Hi, are managed arrays of value types created on the managed heap, just as are managed arrays of reference types ? String* StrArray = new String* ; // Arrays of a Reference type int...
7
by: Ioannis Vranos | last post by:
Consider the code: wchar_t __pin *p= &(someCommand->ToCharArray()); _wsystem(p); p=0;
0
by: Bjoern Jonsson via .NET 247 | last post by:
Hi all, i've just encountered a problem with pinning. it seems as if a managed object is moved altough a pinning pointer to this object is still alive code snippet: ManagedObject __pin*...
9
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
by: Maxwell | last post by:
Hello, Newbie question here. I have a VS.NET 2003 MC++ (not C++/cli) project where I have a managed class reference in a unmanaged class...simple enough. To keep things short I am for the most...
2
by: steve | last post by:
Hi all, I want to understand more about how the pinvoke pinning process works. I'm writing some code that calls DeviceIoControl. DeviceIoControl provides a generic interface to device drivers....
12
by: DaTurk | last post by:
Hi, I have a rather interesting problem. I have a unmanged c++ class which needs to communicate information to managed c++ via callbacks, with a layer of c# on top of the managed c++ ultimatley...
4
by: =?Utf-8?B?VGhlTWFkSGF0dGVy?= | last post by:
I am very sorry to bring a topic up that has been beaten with an ugly stick..... but... If I want to "fix" an byte array for the life time of a program would it be better allocating it on the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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,...

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.