473,842 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's best, return a large string or pass via "ref"?

I have created a function that returns a string containing raw HTML to
be used on a web form (see below):

private string GetReportHTML()
{
string strHTML = "";

// I have some code here that queries a database and
// formats the return DataSet as HTML and inserts
// this HTML into strHTML for return to the calling
// function

return strHTML;
}

This HTML content is a report. As such, there is potential for this
report, and thus the returned string size, to be very large.

My question is this, would there be any performance benefit by
changing this function from returning a string to accepting a "ref
string strHTML", considering this string could be very large? (see
below)

private void GetReportHTML(r ef strHTML)
{
}

Thanks in advance.
Nov 15 '05 #1
3 1755
Since the string type is a reference type, a reference to the string is
already returned from the GetReportHTML() method. Adding a parameter with
the ref keyword won't do anything for you. A ref param would only be used
if you wanted to change which object the parameter referred to, which is not
what you want to do in this case.

Joe
--
http://www.csharp-station.com

"Bob Maggio" <bc*****@yahoo. com> wrote in message
news:ef******** *************** **@posting.goog le.com...
I have created a function that returns a string containing raw HTML to
be used on a web form (see below):

private string GetReportHTML()
{
string strHTML = "";

// I have some code here that queries a database and
// formats the return DataSet as HTML and inserts
// this HTML into strHTML for return to the calling
// function

return strHTML;
}

This HTML content is a report. As such, there is potential for this
report, and thus the returned string size, to be very large.

My question is this, would there be any performance benefit by
changing this function from returning a string to accepting a "ref
string strHTML", considering this string could be very large? (see
below)

private void GetReportHTML(r ef strHTML)
{
}

Thanks in advance.

Nov 15 '05 #2
No. You are already passing back a reference to a string anyway.

-Rob Teixeira [MVP]

"Bob Maggio" <bc*****@yahoo. com> wrote in message
news:ef******** *************** **@posting.goog le.com...
I have created a function that returns a string containing raw HTML to
be used on a web form (see below):

private string GetReportHTML()
{
string strHTML = "";

// I have some code here that queries a database and
// formats the return DataSet as HTML and inserts
// this HTML into strHTML for return to the calling
// function

return strHTML;
}

This HTML content is a report. As such, there is potential for this
report, and thus the returned string size, to be very large.

My question is this, would there be any performance benefit by
changing this function from returning a string to accepting a "ref
string strHTML", considering this string could be very large? (see
below)

private void GetReportHTML(r ef strHTML)
{
}

Thanks in advance.

Nov 15 '05 #3
You probably should to do it a different way altogether. If the report is
large then the string will need to be created in memory. If you have a lot
of people hitting your site you will use much memory.

"Bob Maggio" <bc*****@yahoo. com> wrote in message
news:ef******** *************** **@posting.goog le.com...
I have created a function that returns a string containing raw HTML to
be used on a web form (see below):

private string GetReportHTML()
{
string strHTML = "";

// I have some code here that queries a database and
// formats the return DataSet as HTML and inserts
// this HTML into strHTML for return to the calling
// function

return strHTML;
}

This HTML content is a report. As such, there is potential for this
report, and thus the returned string size, to be very large.

My question is this, would there be any performance benefit by
changing this function from returning a string to accepting a "ref
string strHTML", considering this string could be very large? (see
below)

private void GetReportHTML(r ef strHTML)
{
}

Thanks in advance.

Nov 15 '05 #4

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

Similar topics

3
1986
by: Dmitry | last post by:
Hi, I have defined interface for COM components which inludes an argument being filled with additional error info, if such occurs. If inside I raise COM Error, I populate that parameter. In COM environment this architecture works beautifully -- caller application gets negative HRESULT and error description from IErrorInfo object, and additional "log" information from that "ref" parameter: In .Net it just never returns that paramter...
22
3358
by: Dr Duck | last post by:
GDay all, Something seems odd to me.... I wrote a simple C# function public void bind(ref object a, ref object b, bool atob) { if(atob) b = a; else
5
6710
by: Tee | last post by:
Hi guys, I am confused about the usage of "ref". Please see this code: private void button3_Click(object sender, System.EventArgs e) {
1
1276
by: Kris Takacs | last post by:
Hello, I recently upgraded a project from Visual Studio 6 to .NET and get the following error message when I call help: "The window name "REF" was not defined in your project file." If I click OK, the help comes up... Any ideas?
5
2682
by: Cmtk Software | last post by:
The following code: public __gc class MyClass { public: void MyFunc (int __gc* number); }; Generates the following metadata for C# when compiled in VC 2005 with the /clr:oldsyntax switch in a DLL project:
4
1786
by: Everton Berz | last post by:
Hi, In the follow program I would like to have the parameter "c" in method "doSomething" as a value parameter, but it's running as a reference parameter. Why? How can I get parameter "c" as a value (or clone, copy)? Current result: value1 value2
8
1688
by: not_a_commie | last post by:
A method parameter declared as "const ref" would allow for passing large structs quickly and enforce that the struct does not get reassigned. I know there was concern before about the inability of such a device to enforce that the members don't get set. I don't care about that. Let them assign the members (all of which I've declared readonly.) I've started making most of my structs immutable. They're just so nice to use that way. I just...
0
9872
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10945
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
10672
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
10314
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9453
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 projectplanning, coding, testing, and deploymentwithout 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...
0
5696
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
5885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4499
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
3145
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.