473,322 Members | 1,714 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,322 software developers and data experts.

fast return value

I have a large number of hard coded strings I want to return from a dll.
I'm under the impression the fastest way would be a string array of the type
string[] myarray = {"1","2","3"...}. (I'm under the impression this would
be much faster then adding each string to the array one at a time.) When I
do this, the compiler throws an error saying it has a max line size of 2046.
Is there a way around this or is there another fast/faster way to return the
list of strings.
Thanks,
Rick
Nov 16 '05 #1
3 1386
Rick,
(I'm under the impression this would
be much faster then adding each string to the array one at a time.)
I don't think so, that's what the compiler ends up doing anyway.

When I do this, the compiler throws an error saying it has a max line size of 2046.


Do you have to put them all on one line? Add some line breaks and see
if it works better.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
Mattias:
I don't think so.. I guess that is part of my question, does anyone know for sure whether the
compiled version of : string[] myarray = {"1","2","3"...} is equivalent to
myarray.SetValue("1",1);myarray.SetValue("2",2) etc.

I've seen tests that show their are differences between other similar
operations, like stringa = stringb and stringa.Equals(stringb) etc that show
they are not treated all the same by the compiler, so I don't assume they
are the same in this case.
Do you have to put them all on one line? Add some line breaks and see
if it works better. How do you propose I add line breaks? If I add a cr/lf it reads it as a
syntax error.

Thanks for any other thoughts you might have.
Rick

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:uY*************@TK2MSFTNGP11.phx.gbl... Rick,
(I'm under the impression this would
be much faster then adding each string to the array one at a time.)
I don't think so, that's what the compiler ends up doing anyway.

When I do this, the compiler throws an error saying it has a max line

size of 2046.
Do you have to put them all on one line? Add some line breaks and see
if it works better.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 16 '05 #3
I guess that is part of my question, does anyone know for sure whether the
compiled version of : string[] myarray = {"1","2","3"...} is equivalent to
myarray.SetValue("1",1);myarray.SetValue("2",2) etc.
You don't have to involve SetValue calls, there are IL opcodes to
store array elements. Compile this code

void Foo()
{
string[] arr1 = {"a", "b", "c"};
string[] arr2 = new string[3];
arr2[0] = "x";
arr2[1] = "y";
arr2[2] = "z";
}

and check the result in your favorite disassembler/decompiler, and
you'll see that the two code segments are equivalent.
How do you propose I add line breaks?


string[] s = {
"Your first really long string",
"Your second really long string",
"First part of the third string" +
"Second part of the third string"};

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #4

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

Similar topics

0
by: Peter Otten | last post by:
There is currently a discussion on python-dev about an extract() function which offers fast access to list items and object attributes. It could serve, e. g., as the key argument of the future...
11
by: Ville Vainio | last post by:
I need a dict (well, it would be optimal anyway) class that stores the keys as strings without coercing the case to upper or lower, but still provides fast lookup (i.e. uses hash table). >> d...
13
by: William Stacey | last post by:
FYI. /// <summary> /// Author: William Stacey /// Fast and simple way to implement a singleton pattern without resorting /// to nested classes or other static vodo. Can also be easily converted...
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
10
by: javuchi | last post by:
I just want to share some code with you, and have some comments and improvements if you want. This header file allocates and add and delete items of any kind of data from a very fast array: ...
5
by: Marian Steinbach | last post by:
Howdy! I am just switching from PHP4 to PHP5. Since there are many different ways to create XML in PHP5, I'd like to know from the community which one would be suited best for a REST web service...
33
by: Stef Mientki | last post by:
hello, I discovered that boolean evaluation in Python is done "fast" (as soon as the condition is ok, the rest of the expression is ignored). Is this standard behavior or is there a compiler...
27
by: Mark | last post by:
Hi all, I have a scenario where I have a list like this: User Score 1 0 1 1 1 5 2 3 2 1
14
by: jason.cipriani | last post by:
Two questions: 1. On a modern 32-bit Intel machine, but not using SSE, what is the fastest way to compute the fractional part of a float? E.g., "fmodf(num, 1.0f)", or "num - (float)(int)num",...
2
by: Dinsdale | last post by:
We have created a object library that implements the INotifyPropertyChanged.PropertyChanged to bubble changes up to higher level classes. For instance, we have a person class that can have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.