473,725 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
+ 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 1504
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******@newsg roup.nospam> wrote in message
news:uB******** ******@TK2MSFTN GP12.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.co m

<SH******@newsg roup.nospam> wrote in message
news:uB******** ******@TK2MSFTN GP12.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.ne t> wrote in message
news:%2******** *******@TK2MSFT NGP15.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.c om> schrieb
im Newsbeitrag news:%2******** ********@TK2MSF TNGP11.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.co m

<SH******@newsg roup.nospam> wrote in message
news:uB******** ******@TK2MSFTN GP12.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******@newsg roup.nospam> wrote in message
news:%2******** *******@TK2MSFT NGP12.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
2152
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 access module that creates a large disconnected dataset from a database. I want to pass that dataset back to the calling program. And then perhaps I want to send that dataset to another class module. At first it seems that the "object oriented"...
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 access module that creates a large disconnected dataset from a database. I want to pass that dataset back to the calling program. And then perhaps I want to send that dataset to another class module. At first it seems that the "object oriented"...
7
3581
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 - FirstName - LastName - CompanyId (many-to-one )
3
1494
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 example: var level1={ info:"abc", //lots of other properties here alongside info level2:{ moreinfo:"def", //lots of properties at this level too level3: //various other level 3 objects },
0
8749
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9250
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6699
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6007
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4507
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4777
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3216
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 we have to send another system
2
2627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.