> Erick Thompson spake:
>
> Peter,
>
> Thanks for your great suggestions. I eventually ended up using the last
> method, the one that explicitly created the char array using AllocHGlobal.
> Is this method going to impact performance at all, or is using
> AllocHGlobal
> actually going to speed things up?
>
> Thanks,
> Erick
>

I don't know if it will impact performance. I would expect the AllocHGlobal
method to be one of the fastest methods. Your buffer is uninitialized, the
data is not copied from managed to unmanaged, but only from unmanaged to
managed.

Any managed <-> unmanaged marshaling in .NET typically involves copying
data. So this solution does no more work.

You could possibly use unsafe (but still managed) code in C# to accomplish
this task. If you had an array of Chars, you could pin the array in memory
so that it would not move during garbage collection. Unsafe C# code supports
pointers so you might be able to get a direct pointer the array and then
pass this pointer to unmanaged code. This is all theory of course. I haven't
written any unsafe code yet. It would involve the least amount of copying
though. Unfortunately, if the unmanaged code has a bug and overruns your
buffer on your managed heap you will be in serious trouble!

--
Peter

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to