|
Sounds like a homework/interview question.
Google for the answers, and if you still don't understand something, be specific with your quesion.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Tell me a scenario where we are forced to make a function static
|
|
|
|
|
Hello,
I think you really should do what have been suggested bevor!
Is the reason why you posted the question again (which is very rude for the one who tried to help you) that you haven't understood the answer?
I give you a help to search for at google:
"Singleton"
All the best,
Martin
|
|
|
|
|
I have this suspicion you thanked me with that 1 vote, but I'll give you the benefit of the doubt.
To answer your question: Singletons. Factory methods. Helper classes. Lots of other scenarios where your function should/does not need to do anything with the instance variables.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Vikram A Punathambekar wrote: I have this suspicion you thanked me with that 1 vote
This really sucks!!!
That's why I posted this suggestion[^]
Got my '5' to bring it back in shape!
All the best,
Martin
|
|
|
|
|
Heh, I'm happy to share what little I know, but these little things can be annoying. C'est la vie.
I find it amazing that people like CG, Guffa, you, and a few others plow on with little to no rewards. I'd be happy if I were half as helpful as one of you.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Vikram A Punathambekar wrote: I find it amazing that people like CG, Guffa, you, and a few others plow on with little to no rewards
There are rewards.
1. Occasionally people thank us.
2. It exercises the brain so it helps retain the information we have, even if we aren't working on a project that uses it at this time.
3. If you are helpful enough you get a different icon next to your name.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
I should have included you as well in my list.
What I meant was that people don't get paid for answering these questions like they do for writing code for their employers.
I sometimes forget instant gratification is a myth. However, I'm still young, still learning and determined to 'plow on' like you guys.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Here's a thought, if a function has no state, then why would you want to have to create an object instance, to call it ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
That may be a little beyond him
I think I'm going to call my next project "Chuck Norris". It's a sure way to guarantee it's unbreakable.
• • •
But fortunately we have the nanny-state politicians who can step in to protect us poor stupid consumers, most of whom would not know a JVM from a frozen chicken. Bruce Pierson
|
|
|
|
|
If it is, then there's no point in giving a more direct answer
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
When you can't use the keyword 'this'. (It's basically what Christian said above )
|
|
|
|
|
I strongly advise you to provide at least one static method, you might even want to
call it Main.
|
|
|
|
|
Hello friends,
I am making a small application in which i am reading data from text file
and sending it to speech lib.
In this i want to give pause functionality. Now i want to keep the track of
the line until which the reading has been done. I am storing file name and it's
line number in an xml file. but how should i read the file from specified line number
or word.
Thats my question.
Thanks in advance.
Rahul Kulkarni
|
|
|
|
|
in VB.Net we use StreamReader:
Dim MyFile As New IO.StreamReader(New IO.FileStream("FileAddress", IO.FileMode.Open))
Dim str As String = MyFile.ReadLine
StreamReader is also available in C#
A.E.K
|
|
|
|
|
I'm in a new department that is currently using c++/VS2002.
The lead programmer and myself are have a debate over what the performance differences are between c++ and C#. Googling, I can find only a few things and none of them give a really good comparison. My own feelings are that they are fairly similar overall, but I cannot find any proof.
Can anyone point me where to look to find the info?
Thanks in advance
Tom
|
|
|
|
|
C++ is obviously going to be faster. The *real* question is, how much faster, could you tell the difference for the sort of apps you write, on the hardware it will be run on, and how much more does it cost in man hours to use C++ instead ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
We are building some rather complex applications that all boil down to computational geometry on a complex collections of object. They are really extensions of 3d CAD systems into the manufacturing systems.
We are currently moving from code embedded (think plugin) in CAD system to free standing applications. As a result we really have two issues. The first is a data/object management issue because our data structures become very complex. The text version of the data can be 200+k lines long.
So for these routines, C#'s advantages of no pointers and no memory leaks (both big problems currently) will out way performance issues. The questions on performance have to do with parsing speed and dynamic memory management. Our lead programmer thinks that any system with memory garbage collection has to be too slow by definition and therefore not worth consideration.
The second is a rendering/computationally issues. These will be fairly tightly defined routines where computational speed is an issue, although a difference of 10-20% probably would not be noticed. Especially as processor speeds increase. We are also going to be recoding these for multi-core support, so ease of threading here will be an issue.
In terms of hardware, we are going to be supporting all versions from windows 2000 to vista, both 32 and 64 bit. So porting between these OSs will be a problem. I've seen an article on codeproject that goes over the coding differences between 32 and 64 bit in C++ and it looks like it will be a problem. I believe that .net does this automatically for us. And ultimately Linux, but no customers have requested it. If we limit ourselves to what MONO supports, I think this may be a solution.
This is going to be a 6-8 person project for the next couple of years. We are probably looking at 500k lines of code. So overall programmer efficiency is going to be a really big deal. At a minimum I think that we need to move to VS Team, but am going to have to get more info before I can convince the others.
Thanks for quick reply.
Tom
|
|
|
|
|
Tom Thorp wrote: no memory leaks
Very good joke!
|
|
|
|
|
Tom Thorp wrote: no pointers and no memory leaks (both big problems currently)
Then perhaps moving to C# is a good thing. No well written C++ code will leak, at least not in ways that are 'big problems'. I worked on a 3D home design program in C++, and we didn't have any significant memory leaks.
C# does require you to manage leaks, however, especially for graphics objects.
Tom Thorp wrote: The questions on performance have to do with parsing speed and dynamic memory management. Our lead programmer thinks that any system with memory garbage collection has to be too slow by definition and therefore not worth consideration.
For a CAD system, I suspect he may be right. I have written image processing apps in C#, however, and they work just fine.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Tom Thorp wrote: If we limit ourselves to what MONO supports, I think this may be a solution.
Search for threads about in on the Lounge. MONO has some fairly large sized holes in the base classes. MONO also uses GTK.net for graphics instead of trying to port winforms (too win32 centric in design). Even if none of the former are a problem for you, if a *nix port is in your likely future you'd probably do better writing the UI with GTK.net now instead of having to rewrite it later.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
Christian Graus wrote: C++ is obviously going to be faster.
Not necessarily true, depends heavily on the implementer.
|
|
|
|
|
Hi Tom,
I understand your doubts; we had the same doubts more than ten years ago, when
we considered switching embedded system programming to Java; Java has a similar
garbage collection approach. But we did switch over, and soon we were glad we did
because of the increased programmer efficiency and code robustness.
The garbage collection concept is quite OK if you pay some attention to it.
Of course you must (continue to) care about the number of objects you create; every object
sooner or later must be retrieved to recycle the memory it was occupying.
Switching an image processing application from C++ to C# should not be seen as an
open invitation to turn every pixel into an object...
Here are some examples that limit the object generation rate:
1. when performing complex string operations (say a number of concatenations),
you will be better of using a StringBuilder.
2. short-lived objects, large or small, that only consume a limited number of CPU
cycles in their life span, need special attention, to avoid the gc effort becoming
noticeable. If you currently manage these objects yourself,
you can continue to do this, by recycling them, rather than letting them fade away.
I do not recommend you do this all the time, but when applied to a few classes at
the heart of your application domain, it may prove quite useful.
Of course these examples may seem like giving in on the advantages of C#, but that
would be true only partially and locally. It is similar to general performance optimisation:
in order to improve overall app performance, one must look for hot spots and then give in
a bit to gain some (or a lot).
Hope this may be helpful.
|
|
|
|
|
Hi All,
I have developed a windows application using serialport.
I am able to send the data to the terminal but not receiving it..
here is my code
SerialPort port = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
port.DtrEnable = true;
port.Handshake = Handshake.RequestToSend;
txtData.Text = txtData.Text + port.ReadExisting();
}
Why i'm not able to receive data? whats wrong in my code... Could anyone please help me on this issue...
Thanks in Advance/..
|
|
|
|
|
write instead of your code like this code.
use:
create a delegate like this:
private delegate void Update();
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
port.DtrEnable = true;
port.Handshake = Handshake.RequestToSend;
this.invoke(new invoker Update(this.refresh));
}
private void refresh()
{
txtData.Text = txtData.Text + port.ReadExisting();
}
|
|
|
|