|
You've not provided any useful information. For example:
What doesn't work?
Does it compile/link okay?
Are any assertions fired?
Are any exceptions thrown?
Have you stepped through the code to see which line is in error?
What value(s) do the variables have as you step through the code?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
GTINFO[0]->GetWindowText(ALL[0],(GTINFO[0]->GetWindowTextLength()+1));
That's one weird line of code ....
what exacly you want to do ? get the text from all CEdit and write them to to a file ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
get the string from an edit box and write it to a line in a text file
|
|
|
|
|
why don't you simply call CWnd::GetWindowText( CString& ) ?
seems you are complexifying things a wee bit ...
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
You mast write, won won't work in you code (if you debug it )
For fist look, the general error in that lines :
ANDYFA wrote:
k.Insert(k.GetLength()+1,ALL[0]);
k.Insert(0,"\r\n");
wht you want to do : insert string on 1-st position in zero length string , and then prepend it whith CRFL
Try this:
k += CString(ALL[0])+CString("\r\n")
|
|
|
|
|
Hi,
I have a gui application. Originally the application is written such that all of the processing is done when you receive the OnIdle message. The performance was adequate and both the GUI and the process got enough resources such that the interface worked ok. I decided that it made more sense to move the processing from OnIdle into a separate thread in order to improve performance of the user interface. Unfortunately the opposite happened. Now the GUI is almost dead.
Here's a model of my program:
<br />
UINT Hog(LPVOID p)<br />
{<br />
CThreadView * me = (CThreadView *) p;<br />
return me->MyHog();<br />
}<br />
<br />
UINT CThreadView::MyHog()<br />
{<br />
int x = 0;<br />
while(1)<br />
{<br />
x = x*x;<br />
}<br />
return 0;<br />
}...<br />
AfxBeginThread(Hog, this);<br />
...<br />
First, that's a model, that's not my processing function. Second, there is A LOT of performance improvement if the thread is allowed to run without calling this->Invalidate(). But I need to update the graphical user interface based on what the thread has done. That is I need to repaint the CView.
I've also used SendMessage() (yes I'm aware of deadlock possibility) and PostMessage() to run a function in the "main" thread that just calls this->Invalidate. The performance sucks as well.
I don't have any critical sections/locks on the data so I don't think anyone is waiting.
Any suggestions?
|
|
|
|
|
Can't you just update the GUI in OnIdle as you did before?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Any time you spin in a tight loop in a worker thread, it will suck up as much CPU time as the system will give it. Look in Task Manager and you'll see the CPU pegged.
And since that thread is doing so much work, it ends up posting a ton of messages to the main thread (via Invalidate() , which generates WM_ERASEBKGND , WM_NCPAINT , and WM_PAINT , maybe others too). Since the thread is hogging the CPU, the main thread can't process those messages as quickly as if the thread weren't running.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Ford, what's this fish doing in my ear?
|
|
|
|
|
First of all: lower the priority of your worker thread. Any thread that will take a long time to process data should be low priority so that it doesn't interupt anything else you might want to do while waiting. (such as play a game!) This will at least make sure your GUI thread isn't interupted when it need to do something.
The idea is that for any process that takes a long time, it makes little difference in the long run if other processes interupt it. However, for interactive processes (which normally don't take a long time to run) anything else running will slow it down. So you make your worker threads low priority and it has little effect on them, while it makes the rest of the system seem faster! This comes from scheduler theory, but most CS programs don't require a class that would cover it.
Some ideas: I don't know which is best, if any. Some are sub optimal. Some might not even work.
Instead of sending events, just have your GUI thread repaint on a timer every second.
Have the GUI thread wait on a semophore that your worker thread normally hold. This is hard to describe, basicly you need a way to force the GUI thread to wait until the worker thread has done something before it repaints. You might need a third thread to watch the semaphore and send the message, I can't recall how the API works.
Instead of a full repaint, send a message detailing the progress, and just update the parts of the GUI that change based on status.
In the worker thread only update the GUI every 100 (1000? experiment on different machines to find a good number) iterations through the loop.
|
|
|
|
|
Along with the suggestions already made...
Why invalidate the entire window?
Are you udpating a graph? Can you just redraw the part that changed?
Does your data change that fast? If so, maybe you can not keep up with it visually anyway. You will need to show a 'summary' of some form. Or historize the dat and allow user to select which time frame/ranges he wants to view.
|
|
|
|
|
Thank you for all the suggestions. I'm trying out some of them now. Setting the thread priority to below normal helps, but then when I move the mouse or interact with the gui the thread almost doesn't do anything.
To give you more detail the program is actually capturing images using a camera via a firewire cable. With thread having normal priority the images come in really fast, so fast that the user interface is unusable and the images don't get displayed properly.
I redraw using OpenGL, and I no longer call Invalidate() I just call the GL function that draws the image. The performance is still not as good as the balance I have now from OnIdle.
|
|
|
|
|
OK, you guys are always great at helping young aspiring programmers. Here's my situation:
I need to move files from directory A to directory B. If a file being moved from A exists in B, I want the file from A to overwrite the file in B (regardless of date, size, etc.).
I'm planning on using MoveFile to accomplish this. Pseudo code:
while(more files in directory A)
{
Get next file;
If(file exists in directory B)
{
delete file in directory B;
}
MoveFile(from directory A to directory B)
}
Is this the best way to accomplish what I need to do? I'm using MoveFile instead of CopyFile because I want any security attributes that belong to the file to remain and my understanding is that CopyFile does not get the file's security attributes.
If there is a "more right" way to do this, I'd like to know.
Thanks so much!
Ian
|
|
|
|
|
What you have is fine. You may want to look at the SHFileOperation() API as it will handle multiple files at once and can override any existing files in the destination folder.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
have a look at ShFileOperation maybe it will do more than the more simpler MoveFile.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Thank you both! I appreciate it. I will take a look at shFileOperation.
-Ian
|
|
|
|
|
Hai,
I'm new to programming...I have to calculate some values in a func and get those values outside the func..
ie i'm doing as below
main()
{
float *val1 = NULL;
float *val2 = NULL;
........
myfunc(&val1,&val2);
myfunc2(*val1,*val2);
.........
}
int myfunc(float *V1,float *V2)
{
int cal1 = 10;
.....
*V1 = cal1 / 2; ---> It does'nt give me any error,but when I debug it gives me access violation in memory 0x0000000 here...
*V2 = cal1 / 5;
return 0;
}
where am I going wrong...
Thanks a lot..
|
|
|
|
|
myfunc(&val1,&val2); means you are passing the address of val1. Val1 is a pointer. Try
myfunc(val1, val2);
Also you need to initialize val1 and val2 to point to something. I hope you did that in the .....part of your main.
|
|
|
|
|
No I did'nt initialize anything..
My basic idea is this..I have to compute the values of two float variables in myfunc1 and use those values in myfunc2.How should I do this..
Thanks a lot
|
|
|
|
|
int main()
{
float v1 = 0.0;
float v2 = 0.0;
....
MyFunc(v1,v2);
...
return 0;
}
void MyFunc(float& v1, float& v2)
{
//Change value of v1 & v2
}
"float&" versus just "float" means that you will be passing by reference, not by value. I suggest you look up by value and by reference in your text/reference book to get a better understanding of this concept.
|
|
|
|
|
1. You can use references.
float val1, val2;
myfunc1(val1,val2);
myfunc2(val1,val2);
...
void myfunc1(float & val1, float & val2)
{
val1 = 10/4; etc etc
}
myfunc2 stays the same.
2. If you want to use pointers
float val1, val2;
myfunc1(&val1, &val2);
myfun2(val1,val2);
your functions should remain the same.
|
|
|
|
|
ok first off when passing a pointer as an argument like you have you dont need to do & or * just use the variable name as long as the types match. you also need to either assign your variable something other than NULL either assign another pointer to it or do a new or malloc wicherver you prefer to create your variable, dont forget to delete your variable when your done.
btw that error your getting is that value becuase thats the same value as the pointer your passing
NULL = 0x0000000
<br />
int main()<br />
{<br />
float *var = new float;<br />
float *var1 = new float;<br />
<br />
myfunc(var, var1);<br />
<br />
printf("%f, %f", var, var1);<br />
delete var;<br />
delete var1;<br />
}<br />
<br />
void myfunc(float *var, float *var1)<br />
{<br />
}
|
|
|
|
|
main()
{
float val1 = 0.0;
float val2 = 0.0;
........
myfunc(&val1, &val2);
}
You need to allocate some memory for Val1 and Val2. What you did allocated memory for 2 variables that were capable of storing the memory address of Val1 and Val2, but not the values themselves.
For instance:
int i; //declares that i is an int and allocates memory
int *j; // declares that j can store a memory address to a location in memory that can store an
//integer - but note, no memory has been allocated for that integer here
j= &i; //assign j (capable of storing an address) the address of i (which in turn can store an int)
Hope this helps you....
|
|
|
|
|
The other guys are right. I just want to add some comments.
Pointers are hard for novices. They seperate the experts from the novices!
Don't just fix the code, spend some time to understand what is wrong. User pencil and paper if you must, and trace out exactly what is going on.
It will be helpful to lookup handles as well. What you have done is created a handle (which is a topic even more advanced than pointers), so you will want to see what you have done.
|
|
|
|
|
does anyone know of any good C++/MFC tests that I can download to check my proficiency, or list of interview questions? I've been reading "The Art of Computer Programming" by Donald Knuth and was never more aware of what I don't know until now.
Thanks in advance!
[A brave person isn't always necessarily a smart person]
bdiamond
|
|
|
|
|
bdiamond wrote:
does anyone know of any good C++/MFC tests that I can download to check my proficiency...
Try www.brainbench.com[^].
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|