Marshal.Copy(IntPtr to IntPtr) why is it missing :( in CLR
Hello,
I am striving after Marshal.Copy(IntPtr src,IntPtr dest) implementation!
I need a platfrom independent functionality of block copying in unmanaged heap.
The requirements exclude the use of unsafe pointer like operations as
well as invocing Win32 specific functions.
So far I am doing with by allocating a byte[] in managed heap and
twice calling Marshal.Copy.
(sorry but do not have the code sample handy) It is highly inefficent
first beacuse it requires twice call to Marshal.Copy, second I am
trashing the memory with potentialy huge managed heap allocations,
which leads to expensive GC collections.
I will greatlly appreciate a hint or two about the most efficiant way
of implementing it.
Well I do not want to use platform dependent calls, otherwise I could have used RtlMoveMemory from kernel32.dll
My intention is the code to be portable to MONO Linux.
Oppps i explicitly said the taboo word Lin*x in MS forum ;) lol
As for the C++, I am not sure if its gonna work on Mono too.
It sounds better sollution though.
Since I have never used manged c++ what will be the difference just to PInvoke from c#?
Thanks in advance,
Peter
Is unsafe code out of the question? I believe that given your earlier specifications you indicated that it is, though if you're considering writing c++ it seems that it isn't...
If it is available you could consider writing a unsafe managed memcpy of your own, that would be platform independent (assuming the unmentioned runtime also supports unsafe c# with pointers...).
-josh [MSFT]
http://blogs.msdn.com/joshwil
Well even that M runtime on the L platform should have memcpy in it's C library, since that's part of the C standard. The only problem you'd run into would be that the name of the C library will be different on Linux and Windows. You could do a conditional compile though, and just import memcpy from one or the other depending on if you have a constant such as WIN32 defined.
Or, as Josh says, you could just use unsafe code if you don't mind having unverifiable code.
-Shawn