473,729 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing large amounts of data between classes/functions

Hi,

I'm writing an application that will pass a large amount of data between
classes/functions.

In C++ it was more efficient to send a pointer to the object, e.g structure
rather than passing the actual structure itself.

Is this true of C# also?

What is the best way to pass a large amount of data with different data types?

e.g object could contain some strings, doubles, bytes etc.

Regards
Macca

Jan 23 '06 #1
11 4138
Macca,

I would return a reference to a DataSet, which has the appropriate
information (if it is something where the structure is fluid), or create an
instance of a class which has the specific information, which you can then
return a reference to (instances of classes, not structures are reference
types, and you pass around the reference).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Macca" <Ma***@discussi ons.microsoft.c om> wrote in message
news:54******** *************** ***********@mic rosoft.com...
Hi,

I'm writing an application that will pass a large amount of data between
classes/functions.

In C++ it was more efficient to send a pointer to the object, e.g
structure
rather than passing the actual structure itself.

Is this true of C# also?

What is the best way to pass a large amount of data with different data
types?

e.g object could contain some strings, doubles, bytes etc.

Regards
Macca

Jan 23 '06 #2
Macca wrote:
I'm writing an application that will pass a large amount of data between
classes/functions.

In C++ it was more efficient to send a pointer to the object, e.g structure
rather than passing the actual structure itself.

Is this true of C# also?

What is the best way to pass a large amount of data with different data types?

e.g object could contain some strings, doubles, bytes etc.


Unless you're dealing with large value types (structs) you don't need
to worry about this. See
http://www.pobox.com/~skeet/csharp/parameters.html

Jon

Jan 23 '06 #3
It might be worth pointing out instances are sent by reference in C#
e.g.

private void foo(MyObject obj)
{

}

'obj' is a reference. The exception to this rule is value types
(structs) which includes the String class.

Jan 23 '06 #4
Just to be clear... strings are reference types ... it sounds like your
calling them value types.
"john doe" <sl********@gma il.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
It might be worth pointing out instances are sent by reference in C#
e.g.

private void foo(MyObject obj)
{

}

'obj' is a reference. The exception to this rule is value types
(structs) which includes the String class.

Jan 23 '06 #5
Hi John,

Intersting article. So if I want to pass around a data structure that
contains different types it is best to use a reference object such as a
class? rather than a value type such as a structure?

I am thinking from a performance view.

My app will have 6-7 modules (classes) and will be passing the above data
structure between them.

Regards
Macca

"Jon Skeet [C# MVP]" wrote:
Macca wrote:
I'm writing an application that will pass a large amount of data between
classes/functions.

In C++ it was more efficient to send a pointer to the object, e.g structure
rather than passing the actual structure itself.

Is this true of C# also?

What is the best way to pass a large amount of data with different data types?

e.g object could contain some strings, doubles, bytes etc.


Unless you're dealing with large value types (structs) you don't need
to worry about this. See
http://www.pobox.com/~skeet/csharp/parameters.html

Jon

Jan 23 '06 #6
Hi Nicholas,

Thanks for the advice.

Just to let you know my application will consist of 6-7 modules(classes ) and
this data structure(consi sting of various data types) will be used to pass
data between them. Is it best to use a class for the data structure rather
than any other data type?

Regards
Macca

"Nicholas Paldino [.NET/C# MVP]" wrote:
Macca,

I would return a reference to a DataSet, which has the appropriate
information (if it is something where the structure is fluid), or create an
instance of a class which has the specific information, which you can then
return a reference to (instances of classes, not structures are reference
types, and you pass around the reference).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Macca" <Ma***@discussi ons.microsoft.c om> wrote in message
news:54******** *************** ***********@mic rosoft.com...
Hi,

I'm writing an application that will pass a large amount of data between
classes/functions.

In C++ it was more efficient to send a pointer to the object, e.g
structure
rather than passing the actual structure itself.

Is this true of C# also?

What is the best way to pass a large amount of data with different data
types?

e.g object could contain some strings, doubles, bytes etc.

Regards
Macca


Jan 23 '06 #7
Macca,

If the data structure is large, and you have to pass it around often,
then yes, a class is better, since you will be copying the data on each pass
of the data from one method to the next. If the structure is large, you
will see some performance impact.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Macca" <Ma***@discussi ons.microsoft.c om> wrote in message
news:ED******** *************** ***********@mic rosoft.com...
Hi Nicholas,

Thanks for the advice.

Just to let you know my application will consist of 6-7 modules(classes )
and
this data structure(consi sting of various data types) will be used to pass
data between them. Is it best to use a class for the data structure rather
than any other data type?

Regards
Macca

"Nicholas Paldino [.NET/C# MVP]" wrote:
Macca,

I would return a reference to a DataSet, which has the appropriate
information (if it is something where the structure is fluid), or create
an
instance of a class which has the specific information, which you can
then
return a reference to (instances of classes, not structures are reference
types, and you pass around the reference).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Macca" <Ma***@discussi ons.microsoft.c om> wrote in message
news:54******** *************** ***********@mic rosoft.com...
> Hi,
>
> I'm writing an application that will pass a large amount of data
> between
> classes/functions.
>
> In C++ it was more efficient to send a pointer to the object, e.g
> structure
> rather than passing the actual structure itself.
>
> Is this true of C# also?
>
> What is the best way to pass a large amount of data with different data
> types?
>
> e.g object could contain some strings, doubles, bytes etc.
>
> Regards
> Macca
>


Jan 23 '06 #8
Macca wrote:
Intersting article. So if I want to pass around a data structure that
contains different types it is best to use a reference object such as a
class? rather than a value type such as a structure?

I am thinking from a performance view.

My app will have 6-7 modules (classes) and will be passing the above data
structure between them.


I very, very rarely write my own value types. Performance is usually
less important than getting the right semantics, to be honest - and
reference semantics *tend* to be preferable to value semantics IMO. Of
course, just because they're reference types doesn't mean they have to
be mutable... often an immutable reference type (such as string) gives
the best performance *and* semantics.

Jon

Jan 23 '06 #9
In reference to the above about strings, they behave like value types.
I don't know the internal workings well enough to say whether a
reference is passed or not, however use them like value types is the
easiest solution. e.g.:

private void button1_Click(o bject sender, System.EventArg s e)
{
string s = "moo";
this.foo(s);
MessageBox.Show (s);
}

private void foo(string s)
{
s = "hello";
}

Displays a message box with "Moo", not "hello".

Jan 24 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2488
by: flamesrock | last post by:
Hi, Basically, what I'm trying to do is store large amounts of data in a list or dictionary and then convert that to a custom formatted xml file. My list looks roughly like this: (d,r,p]]]) My question is, would it be faster to use a dictionary if the elements
1
2341
by: michaaal | last post by:
If I use a form to pass data (say, for example, through a textbox) the data seems to be limited to somewhat smaller amounts. What should I do if I want to pass a large amount of data? For example a list of 200 items?
10
2421
by: Digety | last post by:
We are looking to store a large amount of user data that will be changed and accessed daily by a large number of people. We expect around 6-8 million subscribers to our service with each record being approximately 2000-2500 bytes. The system needs to be running 24/7 and therefore cannot be shut down. What is the best way to implement this? We were thinking of setting up a cluster of servers to hold the information and another cluster...
4
3808
by: oshanahan | last post by:
Does anyone have ideas on the best way to move large amounts of data between tables? I am doing several simple insert/select statements from a staging table to several holding tables, but because of the volume it is taking an extraordinary amount of time. I considered using cursors but have read that may not be the best thing for this situation. Any thoughts? -- Posted using the http://www.dbforumz.com interface, at author's request...
3
2849
by: Wayne Marsh | last post by:
Hi all. I am working on an audio application which needs reasonably fast access to large amounts of data. For example, the program may load a 120 second stereo sound sample stored at 4bytes per sample, which would mean over 40MB of data at a 44100Hz sampling rate. Now, what would be a good way to handle all of this data? Ideally, for the sake of my own sanity and the algorithms within directly functional portions of the code, I'd like...
2
5108
by: Dennis C. Drumm | last post by:
What is the best way to add several pages of text to a readonly TextBox? The text does not change and was created in a Word rtf document but could as easly be put in a ASCII text file. Can this be done using a resource or something? Can TextBoxes be attached to data sources other than database objects? Thanks, Dennis
7
10826
by: =?Utf-8?B?TW9iaWxlTWFu?= | last post by:
Hello everyone: I am looking for everyone's thoughts on moving large amounts (actually, not very large, but large enough that I'm throwing exceptions using the default configurations). We're doing a proof-of-concept on WCF whereby we have a Windows form client and a Server. Our server is a middle-tier that interfaces with our SQL 05 database server.
4
1927
by: bcomeara | last post by:
I am writing a program which needs to include a large amount of data. Basically, the data are p values for different possible outcomes from trials with different number of observations (the p values are necessarily based on slow simulations rather than on a standard function, so I estimated them once and want the program to include this information). Currently, I have this stored as a vector of vectors of varying sizes (first vector is...
0
8913
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
9426
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
9200
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
8144
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
6722
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
4525
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
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
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
3
2162
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.