all groups > dotnet general > october 2004 >
You're in the

dotnet general

group:

Any boxing with IndexOf() ?



Any boxing with IndexOf() ? ValyaS
10/1/2004 5:51:05 PM
dotnet general: I have a byte array (myArray) filled by reading bytes from the Com port. And
I need to check for a termination byte (0x00 or "\0") as well as for a
combination of bytes/ASCII characters (myString).

I have to provide best possible performance.

I'm wunderring if there is any internal boxing involved in the statements
like the following:

byte myByte = 0x00;
if (Array.LastIndexOf(myArray, myByte) >= 0)
...

String sbuffer = Encoding.ASCII.GetString(myArray, 0, cnt);
if (sbuffer.LastIndexOf(myString) >= 0)
...

Thanks,
Valentina

Re: Any boxing with IndexOf() ? Jon Skeet [C# MVP]
10/2/2004 7:46:23 AM
[quoted text, click to view]

Yes, that involves boxing because the parameter type is object.

[quoted text, click to view]

There's no boxing in that bit.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Re: Any boxing with IndexOf() ? ValyaS
10/4/2004 11:53:03 AM
Thanks.
And how about the

Encoding.ASCII.GetString(myArray, 0, cnt) ?


Valentina

[quoted text, click to view]
Re: Any boxing with IndexOf() ? Jon Skeet [C# MVP]
10/5/2004 7:08:29 AM
[quoted text, click to view]

No - there's no boxing there. Boxing only occurs when a value type
needs to be treated as an object. myArray is already a reference type,
and the parameters to GetString are (byte[], int, int) so there's no
need to convert either 0 or cnt into an object.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
AddThis Social Bookmark Button