Hello there,

Synopsis
A fixed statement prevents relocation of a variable by the garbage
collector. It sets a pointer to a managed variable and "pins" that variable
during the execution of statement.

Rotor's implementation
Rotor's C# compiler maps pointer variables in fixed statement to managed
pointers and then marks them as pinned. Occassionally garbage collection
occurs during execution of the statement and garbage collector have to
resolve managed pointer to an object (which is expensive operation in
rotor's implementation) in order to realize which object should not be
relocated.

Efficient implementation
In order to reduce probability of dealing carbage collector with resolving
managed pointers compiler should try to pin source object rather then
managed pointer and use unmanaged pointer rather then managed pointer.

constCLI Implementation
I've changed C# compiler in order it tried to create temporary object to pin
and used unmanaged pointer as pointer type in a fixed statement.

Tests
Please see test description on the page http://constcli.sscli.net/fixed.html
(C# code and il generated code comparison). Different tests show strong
advantage of the modified version of the generated il code over original
one.
--
Vladimir Nesterovsky
visit: http://constcli.sscli.net
e-mail: [EMAIL PROTECTED], [EMAIL PROTECTED]
home: http://www.nesterovsky-bros.com

Reply via email to