473,757 Members | 10,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is pinned exactly?

Hi everyone;

I have a class with several members and I pin the first reference field in a
function;

public ref struct MyClass
{
String str1;
List<MySubClass ^^subObjects;
....
};

void ManagedFunc(MyC lass ^class)
{
pin_ptr<const wchar_ts1 = PtrToStringChar s(class->str1);

.....
}

Now the first question is; which objects are pinned? MSDN documentation says
"Pinning a sub-object defined in a managed object has the effect of pinning
the entire object." But what does "the entire object" mean? Is it just str1
and MyClass? Or are the subObjects list and the elements contained in it
also pinned? Does the runtime pin each and every object that can be reached
from the parent object?

A second question. Why is it not possible to pin a reference type directly
using pin_ptr? Like;

pin_ptr<MyClass ^pS = gcnew MyClass();

With GCHandle it's possible to directly pin an object, but as far as I
understand pin_ptr does not allow this semantic.

Regards...
Feb 8 '07 #1
1 1787

"Pierre" <xx@xx.comwro te in message
news:eW******** ******@TK2MSFTN GP03.phx.gbl...
Hi everyone;

I have a class with several members and I pin the first reference field in
a function;

public ref struct MyClass
{
String str1;
List<MySubClass ^^subObjects;
....
};

void ManagedFunc(MyC lass ^class)
{
pin_ptr<const wchar_ts1 = PtrToStringChar s(class->str1);

.....
}

Now the first question is; which objects are pinned? MSDN documentation
says "Pinning a sub-object defined in a managed object has the effect of
pinning the entire object." But what does "the entire object" mean? Is it
just str1
A reference type, such as System::String, can never be a sub object. The
only object that gets pinned is the string instance referenced by str1.

Also, you should please avoid abusing keywords such as class, if you expect
people to take your example code seriously.
and MyClass? Or are the subObjects list and the elements contained in it
also pinned? Does the runtime pin each and every object that can be
reached from the parent object?
Even if you had pinned the parent object, by using a pinning pointer to a
value type (value typed member variables actually are sub-objects), then
only the parent object would be pinned. Reachable objects are not affected,
since the garbage collector can still update the parent object to point to
the new location of the other instances, just not move the parent itself.
>
A second question. Why is it not possible to pin a reference type directly
using pin_ptr? Like;

pin_ptr<MyClass ^pS = gcnew MyClass();

With GCHandle it's possible to directly pin an object, but as far as I
understand pin_ptr does not allow this semantic.

Regards...


Feb 12 '07 #2

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

Similar topics

1
4129
by: goyal | last post by:
Hi, Is there a way to find out which tables/indexes/packages/functions have been pinned in the database? Thanks in advance. Cheers, Sachin
3
3331
by: csomberg | last post by:
I'm doing some performance reviews and wish to know what tables SQL has pinned in memory and which ones have are loaded through usage ... Is there a way ? Thanks, Craig
2
1435
by: Mark Oliver | last post by:
Hi, I want to pass a reference to a char type to a class constructor, then read/write to the passed char later in my code. Are the below Asserts right? Thanks, Mark
7
3882
by: _BNC | last post by:
Another thread mentioned non-Pinned pointers as a possible reason for an Interop bug. I'd like to find out more about how this comes about. I presume that the Garbage Collector makes a sweep, decides to realloc memory that is not pinned, and that the unmanaged code's pointer becomes invalid. How often does the GC run, given a reasonably large app running on a P4 300ghz with over 1 gig ram? I would have thought that it did not need to...
3
1255
by: Ben Schwehn | last post by:
If I pin a member of a garbage collected structure, can I safely assume that the entire struct is pinned? I use something like that: (new whidbey syntax, but that shouldn't make a difference): public ref struct MyStruct {
8
2288
by: ms news group | last post by:
What happens if exception is thown within a fixed block? Will the pinned memory buffer get unpinned? and if the pinning pointer points to a managed memery buffer allocated within the throwing function, will the memory buffer get garbage-collected finally? I check the language spec, also searched the internet, found nothing regarding this question.
9
3565
by: =?Utf-8?B?RWR3YXJkUw==?= | last post by:
I would greatly appreciate some help on passing managed object into unmanaged code. I need to pass a reference (address of) of a managed class into unmanaged code (written by a thrid party). The 3rd party unmanaged DLL will pass this reference into standard Win32 unmanaged static callback function in my code. Inside this unmanaged callback function I need to cast this unmnaged pointer that I have received from 3rd party back into the...
16
3133
by: Atmapuri | last post by:
Hi! It would be great, if the pinned arrays would be garbage collectable. This would greatly reduce the amount of copy back and forth the managed and unmanaged memory. I cant think of a single reason, why the GC should not allow this. It would be also great, if the memory could already be allocated as pinned:
2
2494
by: ChaosMageX | last post by:
I copied some code from a Mono 2.4 library to use in my own application. I'm getting a problem because one of the variable declarations involves the keyword "pinned" between the identifier and the instance name. public override unsafe void PutBytes(byte dest, int destIdx, double value) { base.Check(dest, destIdx, 8); byte* pinned numPtr = $(dest); long* numPtr2 = (long*) &value; *((long*) numPtr) = numPtr2; numPtr =...
0
9489
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10072
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8737
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.