473,398 Members | 2,404 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,398 software developers and data experts.

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(MyClass ^class)
{
pin_ptr<const wchar_ts1 = PtrToStringChars(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 1763

"Pierre" <xx@xx.comwrote in message
news:eW**************@TK2MSFTNGP03.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(MyClass ^class)
{
pin_ptr<const wchar_ts1 = PtrToStringChars(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
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
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
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
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,...
3
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): ...
8
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...
9
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...
16
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
0
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...

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.