473,789 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#-APP: Simple efficiency related questions in C#

7 New Member
Hi all!

I'm new to .NET Platform and got some simple questions about efficiency...

To put you in situation, to say that I'm involved in the writing of a complex regex based lexer for use over the .NET RichTextBox component. Since the lexing is done in realtime at the time the user is typing/editing on the RichTextBox, it is high time consuming, so I'm trying to do the best to get the most efficient code. So here we go:

1. Suppose I declared a simple type variable, int x for example. At some point in the code the value of x is unknown, and I need it to take a specific value. Is more efficient to assign it directly or to check if it has the value I want, and if false, then assign it?

//At this point the value for 'x' is unknown. I need it to take value 0.
OptionA:
x = 0;
OptionB:
if (x != 0) { x = 0; }
2. I have some methods involved in the lexing of text that are called hundred of times. I have some simple type local variables declared inside these methods to control the processing itself. Since simple types in C# are objects, will be more efficient to declare these variables outside the methods as instance variables to avoid the overload of creating and destructing these objects each time the methods are called? Do really worth in terms of efficiency making visible these variables to the rest of the class (which is not a good thing in terms of coding style)?

Thanks in advance!
Nov 28 '07 #1
1 1180
kenobewan
4,871 Recognized Expert Specialist
I'm not sure what course you are doing, but I hope it is free because it appears to worth be nothing. You are learning that's fine but come back when you have a project you are working on and you have problems - you have gotten your hands dirty. I am closing this thread.

MODERATOR
Nov 30 '07 #2

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

Similar topics

30
2130
by: Dimitris | last post by:
Hi folks... As part of an assignment, I have to design and implement a fairly small MYSQL 4.0.17 database for a fictitious travel agency. This database will store data from customers submitting it through application forms. I will test my implementation on an old Linux box (RedHat 6.x with PHP 4.0.5 and MySQL 4.0.17, running on an AMD processor and 64MB of memory). Each APPLICATION form will have 4 parts:
5
1881
by: Haines Brown | last post by:
Re. <title>, my impression has been that a line break is _NOT_ allowed in the contained text. Is that true? Also, I gather a double quotation mark in the text string (and ampersand, etc.) _IS_ acceptable, but not char entities (such as &quote;), decimal characters (such as ‛) or style-sheet defined elements (such as <q>). Re. <meta name="description">, is a line break acceptable here? My impression is that for the enclosed descriptor...
16
2991
by: Harlan Messinger | last post by:
1. CSS has five generic font family specifiers: serif, sans-serif, cursive, fantasy, monospace. IE lets the users select a default proportional font and a default monospace font. Is there any way in IE for a user to indicate more specifically what his preferred fonts are for serif and sans-serif, respectively (at least, if not cursive and fantasy as well)? Do other browsers allow a default font to be specified for all five of these generic...
3
1203
by: Jan Waga | last post by:
Hello, I've written and installed windows service in C#. I have two questions: 1) File.Open("lock", FileMode.OpenOrCreate, FileAccess.Read, FileShare.None) does not create the file even if it doesn't exist. Also:
5
1313
by: Ivan Demkovitch | last post by:
Hi! I'm building my portal and I found that some times I need to dinamically generate address. Since I have many modules and each could have it's own parameters in order to preserve other's modules stuff I try to preserve Query string: string GetQueryString()
3
1463
by: James Simpson | last post by:
Hello, I am currently deploying an ASP .NET based web application via Visual Studio 2005 (so I am using .NET 2.0 technology). The two questions I have are with regards to session state in ASP.NET. The first one is how secure is keeping login information in sessionstate using the inproc model and a cookie configuration? The second question I have relating to session states is for an inproc based sessionstate configuration what would be...
2
1431
by: Mani kansal | last post by:
hi, as m recently get into this field.hav done first module yet and doin 2nd 1.can someone pls guide me as from where i could get the sql related problems so that i can apply my concepts on that(for practice purpose). This would help me a lot 2 make my concepts much clearer. hope u would help me thanks
13
2089
by: John Dann | last post by:
A Python newbie, but some basic understanding of how classes, objects etc work in eg VB.Net. However, I'm struggling a little to translate this knowledge into the Python context. I'm trying to teach myself this aspect of Python by working up a trial project, part of which calls for pulling in data from a serial data connection at regular intervals. It looked sensible to place all the comms procedures/functions in their own class and...
8
3053
AmberJain
by: AmberJain | last post by:
Hello, My new semester has started and I have a subject named DBMS (Database Management System). This is the first time I'm studying databases and so I'm not feeling very enthusiastic about databases (partly because I already had learnt C/C++ and I feel that programming is a lot easier that DBMS). Nevertheless, I must learn at least one DBMS as it is part of my college course. I'm confused and I want some suggestions: Que-1: There are a...
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9506
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
10404
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10193
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
10136
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
9016
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...
0
6761
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();...
1
4089
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2906
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.