IntPtr to fixed bytes array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pitrerK
    New Member
    • Dec 2010
    • 1

    IntPtr to fixed bytes array

    hello

    I wonder if there is any possibility to create IntPtr type to point to bytes array? I tried Marshal.Copy() but mem address was changing all the time. I have code like this :

    Code:
    Random rnd = new Random();
                data = new Byte[100];
                rnd.NextBytes(data);
    unsafe
                {
                    fixed( byte*  wsk = data)
                    {
                        IntPtr unmanagedPointer = wsk;
                    }
                }
    of course it doesn't work :) but that code show what im trying to do. Can anyone tell me what should I do?
  • Raj K
    New Member
    • Dec 2010
    • 9

    #2
    Ideally you should not assume the fixed address of managed code if you think in terms of native code.
    What you can do is to allocate memory using Marshal then copy the content of byte array to the allocated memory then point the IntPtr to that memory

    Comment

    Working...