Show/Hide Toolbars

XSharp

The new FIXED modifier and BEGIN FIXED .. END FIXED keywords allow you to tell the .Net runtime that you do not want a variable to be moved by the Garbage collector.

UNSAFE FUNCTION Start AS VOID
  VAR s := "SDRS"
  BEGIN FIXED LOCAL p := s AS CHAR PTR
      VAR i := 0
      WHILE p[i] != 0
           p[i++]++
      END
  END FIXED
   Console.WriteLine(s)
   Console.Read()
  RETURN

As you can see the BEGIN FIXED statement requires a local variable declaration. The contents of this local (in the example above a CHAR PTR) will be excluded from garbage collection inside the block.

 

Please note:
The FIXED keyword and the example above should be used with extreme care. Strings in .Net are immutable. You normally should not manipulate strings this way !