473,480 Members | 2,123 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1488
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2117
by: Chuck Ritzke | last post by:
I keep asking myself this question as I write class modules. What's the best/smartest/most efficient way to send a large object back and forth to a class module? For example, say I have a data...
4
330
by: Chuck Ritzke | last post by:
I keep asking myself this question as I write class modules. What's the best/smartest/most efficient way to send a large object back and forth to a class module? For example, say I have a data...
7
3562
by: Steve | last post by:
I am building an object library for tables in a database. What is the best practice for creating objects like this? For example, say I have the following tables in my database: User: - Id -...
3
1473
by: d d | last post by:
I have a large object with many sub-objects. They may go down 4 or 5 levels and I'm not sure how best to code a method that does operations on that data. Here's an attempt to make it an isolated...
0
6911
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7091
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6966
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2999
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.