471,348 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Whats the best way to pass raw datablocks between C# objects

Hi,

In our system we get image buffers through a native dll as void*. We want to
manage several of this blocks by C# objects an pass them wen needed to a
native image processing library.

What is the best way to do this? Can I just declare a unsafe pointer as
member of a class?

Best regards

Thomas
Jan 24 '06 #1
5 1421
You can also create managed buffers that will contain the same data as
unmanaged ones, and after processing synchronize managed with unmanaged

IMO another way is to create buffers in the managed side, pin them and then
pass to unmanaged lib.
--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

<SH******@newsgroup.nospam> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
Hi,

In our system we get image buffers through a native dll as void*. We want
to manage several of this blocks by C# objects an pass them wen needed to
a native image processing library.

What is the best way to do this? Can I just declare a unsafe pointer as
member of a class?

Best regards

Thomas

Jan 24 '06 #2
Thomas,

You could create an unsafe pointer, but that would require most of your
code to be marked as unsafe (at least, anywhere that uses it).

A better idea would be to have a managed wrapper that exposes a Handle
property (or whatever you want to call it), which returns an IntPtr which
you can pass back to any unmanaged functions you need to.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<SH******@newsgroup.nospam> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
Hi,

In our system we get image buffers through a native dll as void*. We want
to manage several of this blocks by C# objects an pass them wen needed to
a native image processing library.

What is the best way to do this? Can I just declare a unsafe pointer as
member of a class?

Best regards

Thomas

Jan 24 '06 #3
Hi,

"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
You can also create managed buffers that will contain the same data as
unmanaged ones, and after processing synchronize managed with unmanaged

IMO another way is to create buffers in the managed side, pin them and
then pass to unmanaged lib.


I think Nicholas suggestion is better, you keep the data in the unmanaged
side, not need to copy it and in managed side you just keep a pointer ( an
IntPtr ) to the bufferr
rr

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 24 '06 #4
Thank you very much, I think I now understand it better. So I only have to
mark the the region unsafe that assigns the pointer to the IntPtr. The
IntPtr Variable can be used e.g. assigned to another IntPtr without using
unsafe.

Thomas
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:%2****************@TK2MSFTNGP11.phx.gbl...
Thomas,

You could create an unsafe pointer, but that would require most of your
code to be marked as unsafe (at least, anywhere that uses it).

A better idea would be to have a managed wrapper that exposes a Handle
property (or whatever you want to call it), which returns an IntPtr which
you can pass back to any unmanaged functions you need to.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<SH******@newsgroup.nospam> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
Hi,

In our system we get image buffers through a native dll as void*. We want
to manage several of this blocks by C# objects an pass them wen needed to
a native image processing library.

What is the best way to do this? Can I just declare a unsafe pointer as
member of a class?

Best regards

Thomas


Jan 24 '06 #5
Hi,
<SH******@newsgroup.nospam> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Thank you very much, I think I now understand it better. So I only have to
mark the the region unsafe that assigns the pointer to the IntPtr. The
IntPtr Variable can be used e.g. assigned to another IntPtr without using
unsafe.


No really, the IntPtr will be assigned when you call the external method
using P/Invoke, from that moment all you have to do is carry it around.

You will have to release the memory after you are done with it though

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 24 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Steve | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.