473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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(ref strHTML)
{
}

Thanks in advance.
Nov 15 '05 #1
3 1730
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.google.co m...
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(ref 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.google.co m...
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(ref 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.google.co m...
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(ref 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
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...
22
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
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
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...
5
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...
4
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...
8
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
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
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,...

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.