|
Manikandan wrote:
But i want to do this programmatically
I would have thought that my suggested launching would have worked. If I think of anything else you could try I will let you know.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Well, just a notice - Windows are not realtime OS, if you really need the RT features (for RT controlling a device or something like that) you better to go by some specialized RT OS or get some RT plugin for NT that replaces the standard scheduler.
Even if you set the process realtime priority and thread realtime priority the time scheduler can interrupt your process and will do it usually in the worsest possible time.
|
|
|
|
|
hi thanks for you idea,
i did a google search with the string "Real Time plug in for NT" but i couldn't come across any windows compatible plug in's.
would you please refer me one
|
|
|
|
|
just googled for "RealTime NT"
and got some results
|
|
|
|
|
Hi all,
Apologies if this has already been covered but I could find it anywhere.
The problem that I have is that a piece of software that I am working on used a lot of arrays and matrices (i.e. float* and float**), the problem that we where having was that the program was leaking memory like there was no tomorrow (about a meg every 10secs) and the program was crashing at 'innocent' parts of the code.
After spending quite a while trying to solve these errors I decided to go at it with a sledge hammer and change all of the arrays and matrices to STL vectors (i.e. vector for the arrays and a vector <vector> for the matrices). I've now finished making the changes and the program no longer leaks memory or crashes, however it now runs at about 50% slower. I've changed where the vectors are created so that they are only created once. This has improved things quite a lot however it is still noticibly slower about 10%, does anyone have any other easy optimisation methods that I can implement.
I've left the way that the program accesses the data the same using the [] and [][] brackets.
Any thoughts or suggestions will be gratefully received!
Andy
|
|
|
|
|
Hi,
If the type is known (in your case float) you could write your own vector class.
Do the maintance (new/delete) in there and use the good old (double if necessary) arrays.
Vector classes are always quite slow. If speed is primary you should use arrays.
hope this helps...
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
cheers for your reply, I think I have now located where the bottle neck in the code is! basically we copy a BYTE array (about 23000 elements each time!) into another vector (of type unsigned char) about 20-25 times a second which is slowing the whole process down so I'm now currently looking at optimising the copying process
|
|
|
|
|
One thing to do when copying into vectors is use reserve() first if you know how many ites you need to copy in. Saves a lot of time spent allocating and copying progressively bigger blocks of memory.
Mike
|
|
|
|
|
V. wrote:
If speed is primary you should use arrays.
According to Stroustrup, vectors are as efficient as arrays. (See his web site.) So it must be a question of poor usage.
Kevin
|
|
|
|
|
well, I think that if speed is important, you should go back and figure out why your application is leaking memory ... if using VC++ compile in debug mode, and use the DEBUG_NEW define macro to help you find where exactly is the leak; and/or use BoundChecker or some other 3rd party software helper to find te leaks.
you found ( from you other post ) that you copy a lot of arrays, maybe that's where you are leaking memory ...
remember that for each new there should be a delete and for each new [] there should be a delete []
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
thanks everyone for your suggestions, what I've done is build the release version and it 'appears' to be fast enough for our needs. I'm currently in the process of verifying this through the code.
Andy,
|
|
|
|
|
According to Stroustrup, vectors are as efficient as arrays. (See his web site.) So it must be a question of poor usage.
Kevin
|
|
|
|
|
Hi,
I want to read a line of text from file.
Therefore I use following code:
<br />
do{<br />
fscanf(readfile, "%s", line);<br />
text += " ";<br />
text += line;<br />
}<br />
while(line.Find("\n") < 0);<br />
if I debug I can see that line will contain text until the next whitespace. So far so good, but it seems that text += line; doesn't add this value to text.
Does anybody know why?
tnx!
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
Ignore my response below; I didn't see the CString title!
The first thing that comes to mind why it would not visually append would be that line is not null terminated.
Also I think the debug watch window only displays string values up to a certain length, then its truncated. I know that this was so for VS6, not sure for VS.7
[EDIT]
That is because
text += " "cannot be used on string variables.
I am assuming that text is a character buffer. If this is the case try:
..
_tcscat(text,_T(" "));
_tcscat(text,line);
..
[/EDIT]
I Dream of Absolute Zero
|
|
|
|
|
RChin wrote:
text += " " cannot be used on string variables.
I didn't know that, it worked fine for me, I use it all the time?
line and text are both CStrings, the " " is appended, but the line variable isn't. I suppose this has something to do with the fscanf function, but nonetheless it seems very strange to me.
tnx for the reply though.
PS: I've tried text = text + line; and text.Append(line); too, but nothing...
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
V. wrote:
fscanf(readfile, "%s", line);
...
while(line.Find("\n") < 0);
If line is a CString object, it cannot be used as the third parameter to fscanf() .
Assuming you are wanting to read lines from the file, there are at least two methods that make more sense. The first is to use "%[^\n]" instead of "%s" . This will read everything up to the '\n' character. The second is to create a CStdioFile object and use its ReadString() method.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
tnx, this seems to work fine now
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
The problem lies in
fscanf(readfile, "%s", line);
You cannot pass a CString variable as the parameter to fscanf. In this case it needs a char *
You will have to use a char array, or perhaps line.GetBufferSerLength(?) (see MSDN)
In either case you'll have to have some idea of the expected line length and cope with the possibility of buffer overflow. Think about a complete redesign.
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
Hi,
I have a problem to find a good pattern for Initializing some data once on demand, in a thread-safe manner.
My first (not thread-safe) stab at it would be:
void GetSomething(int index)
{
static CSomethingTable table;
return table[index];
}
I can ry to put a critsect around the table intialization, but I regulary end up with the same problem.
Any takers?
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist Fold With Us! || Agile Programming | doxygen
|
|
|
|
|
What's wrong about wrapping the thing with a critical section. AFAIK this should work:
static CRITICAL_SECTION cs;
static bool initialize_cs()
{
InitializeCriticalSection(&cs);
return true;
}
static bool cs_initialized=initialize_cs();
...
void GetSomething(int index){
EnterCriticalSection(&cs);
static CSomethingTable table;
LeaveCriticalSection(&cs);
return table[index];
} You might want to embellish it by using RAII and stuff, but IMHO this is correct (modulo well known problems with the order of initialization of translation units.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
The frequent scenario I have is the SomethingTable being thread safe itself, only the initializaiton is not.
This works if I make the critical section global static (i.e. I don't care in which order CS'es are initialized, they are initialized before the function is called).
However, I have a CS initialized for every Singleton, even If I never use it. I hoped for something better, but maybe I am desiring to much
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist Fold With Us! || Agile Programming | doxygen
|
|
|
|
|
|
ringle looks good - the sample code even has th destruciton in it
Now I only need a "Mutex" with zero-cost-initializaiton :-/
(I wanted to avoid the "init Critical Section even if we never need the singleton" implementaiton - see also my reply above)
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist Fold With Us! || Agile Programming | doxygen
|
|
|
|
|
Peter, before you go and adopt the double check solution, please be aware that this idiom, appealing as it looks, is fundamentally broken. The most thorough exposition of the problem is given in Bacon et al. paper The "Double-Checked Locking is Broken" Declaration[^]. This issue has been devoted literally thousands of posts on comp.lang.c++ and comp.lang.c++.moderated, with threading experts rejecting its validity and lots of enthusiastics proposing seemingly correct formulations: one could call this problem the Fermat's Last Theorem of multithreaded programming, if you know what I mean (except that the theorem is true )
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Interesting post Joaquín, thanks. I quickly scanned the referenced article. Out of interest do you have any references to techniques that do work correctly?
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|