473,769 Members | 2,134 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 1505
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
2159
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
3584
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
1498
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
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9997
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,...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.