T
TonyJ
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
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