I copied some code from a Mono 2.4 library to use in my own application.
I'm getting a problem because one of the variable declarations involves the keyword "pinned" between the identifier and the instance name.
I've never heard of this keyword before. From what I've read on Googled websites, "pinning" has to with the Garbage Collector not moving its memory location or something like that.
Unfortunately, MS Visual C# Express and its compiler have also never heard of this keyword, since they're shouting about the following errors having to do with that line:
; expected
The name 'numPtr' does not exist in the current context
I tried changing the culprit line's syntax to this:
Unfortunately, MS VC# Express still gives me the error "The name 'numPtr' does not exist in the current context" for the other two lines where it is used.
What is the pinned keyword, and how do I get MS Visual C# 2008 Express Edition to recognize it?
EDIT:
I know there has to be a working equivalent in MS VC# Express, because this is what the code is supposed to look like in MSIL:
So, what is the equivalent to the pinned keyword in MS VC# 2008 Express Edition?
I'm getting a problem because one of the variable declarations involves the keyword "pinned" between the identifier and the instance name.
Code:
public override unsafe void PutBytes(byte[] dest, int destIdx, double value)
{
base.Check(dest, destIdx, 8);
byte* pinned numPtr = $(dest[destIdx]);
long* numPtr2 = (long*) &value;
*((long*) numPtr) = numPtr2[0];
numPtr = null;
}
Unfortunately, MS Visual C# Express and its compiler have also never heard of this keyword, since they're shouting about the following errors having to do with that line:
; expected
The name 'numPtr' does not exist in the current context
I tried changing the culprit line's syntax to this:
Code:
fixed(byte* numPtr = $(dest[destIdx]));
What is the pinned keyword, and how do I get MS Visual C# 2008 Express Edition to recognize it?
EDIT:
I know there has to be a working equivalent in MS VC# Express, because this is what the code is supposed to look like in MSIL:
Code:
.method public hidebysig virtual instance void
PutBytes(uint8[] dest,
int32 destIdx,
float32 'value') cil managed
{
// Code size 28 (0x1c)
.maxstack 6
.locals init (uint8* pinned V_0,
uint32* V_1)
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: ldc.i4.4
IL_0004: call instance void Mono.DataConverter::Check(uint8[],
int32,
int32)
IL_0009: ldarg.1
IL_000a: ldarg.2
IL_000b: ldelema System.Byte
IL_0010: stloc.0
IL_0011: ldarga.s 'value'
IL_0013: stloc.1
IL_0014: ldloc.0
IL_0015: ldloc.1
IL_0016: ldind.u4
IL_0017: stind.i4
IL_0018: ldc.i4.0
IL_0019: conv.u
IL_001a: stloc.0
IL_001b: ret
} // end of method CopyConverter::PutBytes
Comment