M
Martijn Mulder
I try to encapsulate a fixed array in a class, but the only thing I know so
far is that this code compiles. Does it give access to a fixed array? What
are the gotcha's?
//class FixedArray
class FixedArray
{
//data bytes
byte[] bytes;
//constructor
public FixedArray(int a)
{
bytes=new byte[a];
}
//property IntPtr
unsafe public System.IntPtr IntPtr
{
get
{
System.IntPtr a;
fixed( byte * b = bytes )
{
a=(System.IntPtr)b;
}
return a;
}
}
}
//class EntryPoint
class EntryPoint
{
//method Main
static void Main()
{
FixedArray fixedarray=new FixedArray(512);
System.IntPtr intptr=fixedarray.IntPtr;
//does intptr point to a fixed array?
}
}
far is that this code compiles. Does it give access to a fixed array? What
are the gotcha's?
//class FixedArray
class FixedArray
{
//data bytes
byte[] bytes;
//constructor
public FixedArray(int a)
{
bytes=new byte[a];
}
//property IntPtr
unsafe public System.IntPtr IntPtr
{
get
{
System.IntPtr a;
fixed( byte * b = bytes )
{
a=(System.IntPtr)b;
}
return a;
}
}
}
//class EntryPoint
class EntryPoint
{
//method Main
static void Main()
{
FixedArray fixedarray=new FixedArray(512);
System.IntPtr intptr=fixedarray.IntPtr;
//does intptr point to a fixed array?
}
}