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 / C# / February 2008

Tip: Looking for answers? Try searching our database.

about references and pointers

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TonyJ - 25 Feb 2008 06:58 GMT
Hello!

You can write  int[] vektor = new int[5];
This array will be stored on the heap and you will have a reference(vektor)
to this array. As long as you keep a reference to this array will GC never
remove
this array.
If you for example set vektor = null then you give the GC permission to
remove this array.

Now to my question which is about unsafe code which is pointer

If you write int * vektor = new int[5];
This will not compile becuse array is reference types.
You must pinning is this way.
(fixed) {int * vektor = new int[5]; }

But I can't understand why you must use (fixed) ?
I mean when you use reference types you never have to use fixed only when
use
unsafe code like pointers.

I mean a reference is only a hidden pointer.

//Tony
Alberto Poblacion - 25 Feb 2008 07:13 GMT
> You can write  int[] vektor = new int[5];
> This array will be stored on the heap and you will have a
[quoted text clipped - 18 lines]
>
> I mean a reference is only a hidden pointer.

  The problem is that the memory allocated to a reference type can move
around when the Garbage Collector runs. The GC will adjust references so
that they still "point" to their object after collecting memory. But if you
use a pointer and the memory moves, it would point to a "wrong" place.
That's why you write "fixed", in order to lock the memory to which the
pointer is pointing so that the GC doesn't relocate it.

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.