Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2007

Tip: Looking for answers? Try searching our database.

What is pinned exactly?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pierre - 08 Feb 2007 15:03 GMT
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_t> s1 = 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...
Ben Voigt - 12 Feb 2007 15:03 GMT
> Hi everyone;
>
[quoted text clipped - 19 lines]
> 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;
[quoted text clipped - 5 lines]
>
> Regards...

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.