473,796 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3562
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**********@d iscussions.micr osoft.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.co m>
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
1787
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
3537
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 and if I remove register type for "l" , time of generating codes doesn't change the original code makes some files , but I removed that section to make it simple for you to read please help me to optimize it for faster running
0
2424
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 the client's data. If I comment out the parser call I can see that the transmition time of large data files is very low. My understanding is that a SAX parser should transmit the content of a CDATA string downstream without signiificant...
5
2855
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
1563
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 standard edition of VC++ yet? Don't think that we've forgotten about it.... Thank, Brian From: Ronald Laeremans (ronaldl@online.microsoft.com)
2
1780
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 this in c# instead of in perl because the log files are 3-4GB and I want faster processing than perl would typically provide. And, I'm learning c#.
3
1279
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 GetOracleClientConnectionString() { string strConnectionString = System.Configuration.ConfigurationSettings.AppSettings;
3
1807
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" T="2005-09-09" Q="10" V="27.50" />
1
1593
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 optimization of query processing. Should I split them into several tables to optimize query processing time? But if I split them, will it guarantee that my query processing time will be faster? As we know, if we split it into several tables, there must be...
0
9533
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10190
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9057
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7555
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.