Clock Problem (VA ST vs. Dolphin ST) 
Author Message
 Clock Problem (VA ST vs. Dolphin ST)

Dolphin Smalltalk has an example code on running a clock which works
and did not eat up all of the CPU time. Cool, huh?

   I modified the clock code for VisualAge Smalltalk and a test code is:
Note: I'm writing this code from memory - I may not have all the details
right.

[ 6 timesRepeat:            "I limited repeat time for testing purposes."
   [ Delay wait: 1000.      " A code to tell it to wait 1 second"
   (subpartNamed: aLabel)text: Time now printString.
                            "Update the label part to display the Time text"
   ]
] fork.

   The code is somewhat similar to the Dolphin example. However, when I ran
it,
 it ate up 100% of the cpu time and did not update the label display until
the loop is finished. That is very uncool.
   I think this process & cpu usage in VisualAge Smalltalk may have been
discussed
before but I can't remember where I have read it. I can't seem to find out
the reason why this is happening. Did I missed a page in David N. Smith's
IBM Smalltalk book?
   Can anyone shed light on this?
--
Larry Trutter



Wed, 18 Jun 1902 08:00:00 GMT  
 Clock Problem (VA ST vs. Dolphin ST)
Hi Larry,

To stop the process eating up all of the CPU time try forking the process at
a lower priority, say userBackgroundPriority.  If that fails, instead of
using a process with a delay to update the clock display try using the OS
API to set up a call back function.

HTH,
Gary



Wed, 18 Jun 1902 08:00:00 GMT  
 Clock Problem (VA ST vs. Dolphin ST)

writes:

Quote:

>[ 6 timesRepeat:            "I limited repeat time for testing purposes."
>   [ Delay wait: 1000.      " A code to tell it to wait 1 second"
>   (subpartNamed: aLabel)text: Time now printString.
>                        "Update the label part to display the Time text"
>   ]
>] fork.

I tried this example in VAST 4.5 except that I wrote to the transcript
and it worked fine. While the process was running I could click around on
other windows and things were quite responsive.

BTW the delay is:

   (Delay forMilliseconds: 1000) wait.

So the problem lays somewhere or somehow in the message to the part.

Appended below is the code for a class that puts up a window and displays
the time in in. It uses Arial Bold and has only been tested on Windows
95. On other platforms it will probably be necessary to change the font
name (in #loadFont) or do a search for a font with suitable
characteristics (which is the portable way to do it).

This example is cerainly longer than the nice Dolphin demo example, but
this one uses the standard Common Widgets hierarchy including callbacks,
and it searches for and loads a font, both of which take a bit to set up.
It builds a real window with real controls. It also cleans up after
itself when the window is closed.

Note the code in #startProcess which displays the time; it uses a 100 ms
wait so that the time always displays evenly (to the human eye). Using
1000 ms can cause the time to seem to skip a second now and then since
the total running time of the loop exceeds 1000 ms by the time spent
outside the wait.

The update frequency of the clock will degrade if you have lots of other
processes running, especially ones of higher priority. The clock runs at
user background priority.

Dave

Object subclass: #ClockDisplay
    instanceVariableNames: 'shell main title text process fontList '
    classVariableNames: ''
    poolDictionaries: 'CwConstants '!

!ClockDisplay publicMethods !

destroy: widget clientData: clientData callData: calData

        fontList notNil ifTrue: [
                fontList fontStruct freeFont ].

        process notNil ifTrue: [
                process terminate ]!

loadFont
        | fontName fontStruct |

        fontName := '-microsoft-arial-bold-i-normal-sans
serif-0-240-96-96-p-0-iso8859-1'.

        fontStruct := shell display loadQueryFont: fontName.
        fontStruct isNil
                ifTrue: [ CwMessagePrompter errorMessage: 'Failed to load font' ]
                ifFalse: [
                        fontList := CwFontList fontStruct: fontStruct.
                        text fontList: fontList ]!

open

        shell := CwTopLevelShell createApplicationShell: 'Time Window'
                argBlock: [ :w | w
                        width: 150; height: 40;
                        mwmDecorations: MWMDECORALL |
                                MWMDECORMINIMIZE | MWMDECORMAXIMIZE ].
        shell addCallback: XmNwindowCloseCallback
                receiver: self
                selector: #destroy:clientData:callData:
                clientData: nil.

        main := shell createMainWindow: 'main' argBlock: nil.
        main manageChild.

        text := main
                createLabel: 'time display'  "$NON-NLS$"
                argBlock: [ :w | w
                        labelString: Time now printString ].
        self loadFont.
        text manageChild.

        shell realizeWidget.   " Window is now on screen "

        self startProcess!

startProcess

        process := [    
                | delay |
                delay := Delay forMilliseconds: 100.
                [ true ] whileTrue: [
                        delay wait.
                        text labelString: Time now printString ]
        ] forkAt: Processor userBackgroundPriority! !

Run this with:

        ClockDisplay new open

_____________________________________________
David N. Smith
IBM T J Watson Research Center, Hawthorne, NY

Home Page: http://www.dnsmith.com/
_____________________________________________
Any opinions or recommendations are those
of the author and not of his employer.



Wed, 18 Jun 1902 08:00:00 GMT  
 Clock Problem (VA ST vs. Dolphin ST)
Thanks for the code example. I'll try it and study really, really
hard to see what the difference is.

I neglected to mention that I use Windows NT but I'm not sure if
it made any difference. I had used its task manager to check the
cpu usage.

I do agree that somehow there is a problem with a message to a
part. I had that problem before in the past.

Thanks again and I'll let you know how it turns out.

Larry



Wed, 18 Jun 1902 08:00:00 GMT  
 Clock Problem (VA ST vs. Dolphin ST)
Larry, check out http://lamplight.terabit.net/vafree.htm for Patrick
Ma's Timer Part which may help.

Andrew McQuiggin

Quote:

> Dolphin Smalltalk has an example code on running a clock which works
> and did not eat up all of the CPU time. Cool, huh?

>    I modified the clock code for VisualAge Smalltalk and a test code is:
> Note: I'm writing this code from memory - I may not have all the details
> right.

> [ 6 timesRepeat:            "I limited repeat time for testing purposes."
>    [ Delay wait: 1000.      " A code to tell it to wait 1 second"
>    (subpartNamed: aLabel)text: Time now printString.
>                             "Update the label part to display the Time text"
>    ]
> ] fork.

>    The code is somewhat similar to the Dolphin example. However, when I ran
> it,
>  it ate up 100% of the cpu time and did not update the label display until
> the loop is finished. That is very uncool.
>    I think this process & cpu usage in VisualAge Smalltalk may have been
> discussed
> before but I can't remember where I have read it. I can't seem to find out
> the reason why this is happening. Did I missed a page in David N. Smith's
> IBM Smalltalk book?
>    Can anyone shed light on this?
> --
> Larry Trutter



Wed, 18 Jun 1902 08:00:00 GMT  
 Clock Problem (VA ST vs. Dolphin ST)


Quote:
>Dolphin Smalltalk has an example code on running a clock which works
>and did not eat up all of the CPU time. Cool, huh?

>   I modified the clock code for VisualAge Smalltalk and a test code is:
>Note: I'm writing this code from memory - I may not have all the details
>right.

>[ 6 timesRepeat:            "I limited repeat time for testing purposes."
>   [ Delay wait: 1000.      " A code to tell it to wait 1 second"
>   (subpartNamed: aLabel)text: Time now printString.
>                        "Update the label part to display the Time text"
>   ]
>] fork.

>   The code is somewhat similar to the Dolphin example. However, when I ran
>it,
> it ate up 100% of the cpu time and did not update the label display until
>the loop is finished. That is very uncool.
>   I think this process & cpu usage in VisualAge Smalltalk may have been
>discussed
>before but I can't remember where I have read it. I can't seem to find out
>the reason why this is happening. Did I missed a page in David N. Smith's
>IBM Smalltalk book?
>   Can anyone shed light on this?

Download the timer off our web site and use that to fire the clock.

GO SMALLTALK


http://www.totallyobjects.com - THE Smalltalk resource

Totally Objects is an IBM Object Connection member



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. ST vs Java vs ST vs ....

2. Generic Server for Dolphin now has web server with ST servlets and ST server pages

3. Europe/Germany+Austria: Smalltalk developper (ENFIN-ST/ObjectStudio + VA-ST)

4. VisualWorks vs Dolphin ST

5. Dolphin ST vs VisualWorks

6. Comparison: ST-80 vs. ST-V

7. ST-80/OS/2 vs. ST-80/Windows

8. Installing VA/ST...Problems.

9. VA ST 3.0 problems

10. VA for ST ver 4.0 problems

11. VA ST: Comctl32 listview control problem

12. VA ST 4.0 Report Font problem - Help

 

 
Powered by phpBB® Forum Software