If you need global mem (and not sure you do), here is a sample:
private void button30_Click(object sender, System.EventArgs e)
{
IntPtr savePtr = Marshal.AllocHGlobal(1024);
ClassWithPointer cwp = new ClassWithPointer();
unsafe
{
byte * p = (byte*)savePtr;
p++; //Use the pointer for stuff...
cwp.i = 118;
cwp.pointer = p; //save the pointer in your class.
//...
Console.WriteLine("cwp.i:"+cwp.i);
Console.WriteLine("cwp.pointer:"+(int)cwp.pointer );
}
Marshal.FreeHGlobal(savePtr); //Free the global memory.
}
public unsafe class ClassWithPointer
{
public int i; //Using public for quick example. These would be private
normally.
public byte* pointer; //byte pointer you hold in your class.
public ClassWithPointer()
{
i = 0;
pointer = null;
}
}
--
William Stacey, MVP
"Fernando Cacciola" <fe***************@hotmail.com> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
For fast image procesign code I need pointers to the elements of a two
dimensional array:
mData = new int[mH,mW];
mScan0 = &mData[0,0];
however, the above won't compile since AFAICT fixed blocks require "local"
pointers:
fixed ( int* lScan0 = &mData[0,0] )
{
// this works
}
while I need the pointer to be a data member of the class (since client
objects use the scanline pointer to access the image).
If the above cannot be done with arrays, are there other block memory
allocation methods?
I figure that this should be possible since
System.Drawing.Imaging.BitmapData contains a field Scan0 which is
effectively a pointer to the Bitmap data array.
TIA
Fernando Cacciola
SciSoft