fast return value

  • Thread starter Thread starter Rick Navaro
  • Start date Start date
R

Rick Navaro

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
 
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:
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
 
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
 
Back
Top