Click to See Complete Forum and Search --> : Tough question, please help a fellow programmer


Cipherous
October 22nd, 2004, 03:14 PM
great board btw,

I am working with some old com files which require data stored in byte arrays and I need to do this

I have the following:

int memoryAddress; //this is where the starting data is stored, its a file
int sizeOfFile;//size in terms of bytes

I need to assign a byte pointer to wherever address the file is

so I want to do this

byte* myData = whateverIsAtMemoryLocation (memoryAddress);

after that, I want to convert that file to a byte array so that I can store it else where

byte[] newData = new byte [sizeOfFile];

for (int i=0;i<sizeOfFile;++i)
newData[i]=(byte)(myData+i);


can anybody please help? when you go myData++, does it go to the next byte in memory? or does it do something else?

my gratitude in advance.

Cipherous
October 22nd, 2004, 03:45 PM
also, does anybody know how to print out the memory address of a pointer?

I tried

MessageBox.Show ("Address of Pointer: "+&myPointer);

and that doesn't compile

I tried

MessageBox.Show ("Address of Pointer: "+(int)(&myPointer));

can anybody help?

darwen
October 22nd, 2004, 04:16 PM
For (2) Have a look at the 'fixed' keyword - this may fulfill your needs.

For (1), if you've got a pointer to a block of memory use the

System.Runtime.InteropServices.Marshal.Copy

methods to copy to and from unsafe, unmanaged memory into managed memory.

See no big deal.

Darwen.

Cipherous
October 25th, 2004, 01:00 AM
For (2) Have a look at the 'fixed' keyword - this may fulfill your needs.

For (1), if you've got a pointer to a block of memory use the

System.Runtime.InteropServices.Marshal.Copy

methods to copy to and from unsafe, unmanaged memory into managed memory.

See no big deal.

Darwen.


woot, System.runtime.marshal was a huge help

thanks alot!