about references and pointers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TonyJ

    about references and pointers

    Hello!

    You can write int[] vektor = new int[5];
    This array will be stored on the heap and you will have a reference(vekto r)
    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


Working...