473,398 Members | 2,120 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,398 software developers and data experts.

Any boxing with IndexOf() ?

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
Jul 21 '05 #1
3 1211
ValyaS <Va****@discussions.microsoft.com> wrote:
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)
...
Yes, that involves boxing because the parameter type is object.
String sbuffer = Encoding.ASCII.GetString(myArray, 0, cnt);
if (sbuffer.LastIndexOf(myString) >= 0)
...


There's no boxing in that bit.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Thanks.
And how about the

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

"Jon Skeet [C# MVP]" wrote:
ValyaS <Va****@discussions.microsoft.com> wrote:
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)
...


Yes, that involves boxing because the parameter type is object.
String sbuffer = Encoding.ASCII.GetString(myArray, 0, cnt);
if (sbuffer.LastIndexOf(myString) >= 0)
...


There's no boxing in that bit.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3
ValyaS <Va****@discussions.microsoft.com> wrote:
And how about the

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


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4

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

Similar topics

14
by: Lora Connors | last post by:
What is Boxing & UnBoxing in .NET?
43
by: Mountain Bikn' Guy | last post by:
I have a situation where an app writes data of various types (primitives and objects) into a single dimensional array of objects. (This array eventually becomes a row in a data table, but that's...
1
by: Tom | last post by:
Couple of questions relating to boxing. Firstly, I already know that boxing is the processing of temporarily copying a ValueType (e.g. struct, enum) to the heap so that the system can treat a...
24
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When...
4
by: Peter Olcott | last post by:
I want to be able to make my .NET applications run just as fast as unmanaged C++. From my currently somewhat limited understanding of the .NET framework and the C# language, it seems that...
3
by: ValyaS | last post by:
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...
14
by: dave.dolan | last post by:
Basically I'd like to implement the composite design pattern with leaves that are either of reference or value types, but even using generics I can't seem to avoid boxing (using ArrayList or...
19
by: ahjiang | last post by:
hi there,, what is the real advantage of boxing and unboxing operations in csharp? tried looking ard the internet but couldnt find any articles on it. appreciate any help
161
by: Peter Olcott | last post by:
According to Troelsen in "C# and the .NET Platform" "Boxing can be formally defined as the process of explicitly converting a value type into a corresponding reference type." I think that my...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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 project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.