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

Optimizing C# String Processing

Hello,

I would like to maximize efficiency of string processing in my C#
application that works with Skype API. Actually, these "strings" are made of
"chars" that are all 8-bit values except 0 (1-255).

1. Is there a way to make C# use 8-bit char so that the memory usage is
reduced?

2. Should StringBuilder be used in place of string while they are being
processed? I haven't done it so far since StringBuilder doesn't have Trim,
StartWith, Substring, & Split functions that I use extensively. Would it be
more efficient to use StringBuilder and convert to string for these missing
functions?

3. Is there an encoding that can efficiently convert byte value (0-255) into
non-zero byte values (1-255)?

4. Are there any other things I should be looking for to raise efficiency?

Regards,
Vinay Agarwal
Nov 17 '05 #1
4 3540
Actually, these "strings" are made of
"chars" that are all 8-bit values except 0 (1-255).
Just the fact that you put strings in quotes is a clear indication
that you're using the wrong data type.

1. Is there a way to make C# use 8-bit char so that the memory usage is
reduced?
No, but why aren't you using a byte array instead of strring/char?

2. Should StringBuilder be used in place of string while they are being
processed?


That's usually a good idea, yes.
Mattias

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


Vinay Agarwal wrote:
Hello,

I would like to maximize efficiency of string processing in my C#
application that works with Skype API. Actually, these "strings" are made of
"chars" that are all 8-bit values except 0 (1-255).
Are you actually having any efficiency problems? Does the profiler
indicate so?
1. Is there a way to make C# use 8-bit char so that the memory usage is
reduced?
How large are those strings? you may be able to "save" half the mem by
using a byte[] representation, but really, are you having memory problems?
2. Should StringBuilder be used in place of string while they are being
processed? I haven't done it so far since StringBuilder doesn't have Trim,
StartWith, Substring, & Split functions that I use extensively. Would it be
more efficient to use StringBuilder and convert to string for these missing
functions?
"While they are being processed"?

StringBuilder *builds* strings, and is good if you concatenate many
strings together, but if you are calling StartWith, Substring & Split,
you are not concatenating.
3. Is there an encoding that can efficiently convert byte value (0-255) into
non-zero byte values (1-255)?


You are not suggesting to complicate your memory representation by
compressing from the domain 1-255 into 0-255, are you?

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 17 '05 #3
Vinay Agarwal <Vi**********@discussions.microsoft.com> wrote:
I would like to maximize efficiency of string processing in my C#
application that works with Skype API. Actually, these "strings" are made of
"chars" that are all 8-bit values except 0 (1-255).
Hmm... are they *actually* text characters, or are you really just
representing binary data?
1. Is there a way to make C# use 8-bit char so that the memory usage is
reduced?
Well, you could use a byte array instead - but then you can't treat it
like a string. You could write your own class which had string-like
facilities, but if you needed to display it (or the like) you'd need to
convert it to a string.
2. Should StringBuilder be used in place of string while they are being
processed? I haven't done it so far since StringBuilder doesn't have Trim,
StartWith, Substring, & Split functions that I use extensively. Would it be
more efficient to use StringBuilder and convert to string for these missing
functions?
StringBuilder can help if you don't need the intermediate values, but
it's no use otherwise.
3. Is there an encoding that can efficiently convert byte value (0-255) into
non-zero byte values (1-255)?
Well, you'll need some sort of escaping, effectively - for instance,
making 255 255 represent 255, but 255 1 represent 0, leaving all other
values as they are. It's not going to be terribly pleasant either way.
4. Are there any other things I should be looking for to raise efficiency?


Well, firstly, do you know that you've got a problem? It's not worth
wasting time and potentially making your code less elegant if you don't
have a performance problem in real life.

Secondly, if you're actually dealing with binary data, don't try to
treat it like a string - you'll end up with really nasty bugs that way.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
Sorry for the late response, I was interrupted by other tasks. From your
feedbad, I understand that I need to look into optimization as a whole and
not focus on strings only. I just started looking into profiler tools--not
sure which is the best, but I will start out with dotTrace. Thanks for your
help.

Regards,
Vinay Agarwal
Nov 17 '05 #5

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

Similar topics

15
by: Jacek Generowicz | last post by:
I have a multiple disptacher which, conceptually, looks something like this: class Multimethod: def __init__(self): self.methods = {}
5
by: ArShAm | last post by:
Hi there Please help me to optimize this code for speed I added /O2 to compiler settings I added /Oe to compiler settings for accepting register type request , but it seems that is not allowed...
0
by: Aidan | last post by:
The setup: a Sax parser in a servlet and a Java client (same machine) which uploads an XML document containing CDATA elements which hold base 64 encoded binary files. The servlet then SAX parses...
5
by: prcpani | last post by:
I have a program that will read as follows #define MS(x) memset(x.arr,'\0',sizeof(x.arr­)) void memset_var() { int cnt =0;
2
by: Brian | last post by:
In particular, this question goes out to the Microsoft C++ development team. Back in June, Ronald Laeremans posted the following message. Has the optimizing compiler been included with the...
2
by: Michael Powe | last post by:
Hello, I have written a small app to parse web log files and extract certain lines to another file. There is also functionality to count all the items that are being filtered out. I wrote...
3
by: Diffident | last post by:
Hello All, I need some help on optimizing a piece of code. Currently this is how we retrieve our Oracle's connection string for executing all the queries in our application. public string...
3
by: Nick Gilbert | last post by:
Hi, I have to send an array of prices for a list of products over XML. Currently my XML data looks like this: <ArrayOfProd> <Prod Code="productcode001"> <Prices> <P F="2005-01-01"...
1
roswara
by: roswara | last post by:
Dear all, Does anyone know the maximum amount of columns of a table in a database? Currently, I am using SQL Server 2005. Is it normal to have 50 columns in a table? I wonder about the...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.