PDA

View Full Version : co2 hellowin1 compiles but...



efgee
01-09-2010, 02:13
Hi,
I've copied hellowin1.tbasic to hellowin1.bas and deleted all tbasic stuff in order to get a pure oxygen source file.

It compiles fine with co2 but the compiled application has a cpu load of 50% on a intel cpu with hyperthreading.

The only way I could get the program to operate normally was to change the message loop to:



;MESSAGE LOOP
;
do while GetMessage (&wm, 0, 0, 0) > 0
TranslateMessage (&wm)
DispatchMessage (&wm)

sleep(1)
wend


As it can be seen I've added a sleep command.
Sleep (Win32 API) takes int numbers as milliseconds; so putting the application to sleep for 1 millisecond did the trick.

My question though is:
I've never had to add a delay in a windows application message loop in order to bring the cpu load down. (with different compilers and languages...)

This doesn't happen if I compile hellowin1.tbasic (the thinbasic interpreter is invoked) but happens if hellowin1.bas is directly compiled as:

co2 hellowin1

Did I miss something?


Bye
efgee

Charles Pegge
01-09-2010, 16:08
Hi efgee,

I don't know what is causing that. Could it be another process thread? My compiled HelloWin1 runs as impassive as a rock. (My PC has an Intel quad core running Vista 64).

In a few days time I will have the bare bones standalone Oxygen with an IDE (Scintilla based) with a linked in Help file. I think this will be easier for you to experiment with. You will be able to compile programs on a single keystroke (F7) or run then directly from script like thinBasic (F5).

Scintilla is new territory for me. The config system is quite complex but I am gradually gaining its cooperation.

Charles

efgee
01-09-2010, 21:20
I don't know what is causing that. Could it be another process thread?


Well, I'm looking at the cpu resources with ProcessExplorer, and it tells me it's the hellowin1 application, not another thread.



My compiled HelloWin1 runs as impassive as a rock. (My PC has an Intel quad core running Vista 64).


I run it on WinXP-SP3, maybe there is a difference.

So you did not observe the cpu load of hellowin1 when thinbasic is not invoked?

[quote=Charles Pegge]
In a few days time I will have the bare bones standalone Oxygen with an IDE (Scintilla based) with a ]

Wow, didn't expect this one... looking forward to it.

Take care
efgee

efgee
01-09-2010, 21:54
So after looking more in depth I found a clear explanation what's happening here:

http://msdn.microsoft.com/en-us/library/ms644936%28VS.85%29.aspx

According to this Microsoft document things like:



do while GetMessage (&wm, 0, 0, 0)
....


should be avoided because the return value can be nonzero, zero, or -1.

So I changed the loop to:



;
; bRet needs to be defined before use...
;
;MESSAGE LOOP
;
do while (bRet = GetMessage (&wm, 0, 0, 0) != 0)

if bRet == -1 then
'do something after the error occurred and show an error message
else
TranslateMessage (&wm)
DispatchMessage (&wm)
end if

wend
;


and this works perfectly.

Maybe the examples that incorporate a gui should get the message loop changed accordingly.

Thanks
efgee

BTW I like the fact that oxygen understands C to some a degree; this way I can use stuff like "==" and "!=" and it works!

Charles Pegge
02-09-2010, 00:10
In Oxygen, the assign and compare operator is ':='

See if this works on your PC:



sys bRet
'
do while bRet := GetMessage (&wm, 0, 0, 0)
if bRet == -1 then
'do something after the error occurred and show an error message
else
TranslateMessage &wm
DispatchMessage &wm
end if
wend


Charles

efgee
02-09-2010, 00:31
Works, thank you.

efgee