Delay forMilliseconds:

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Delay forMilliseconds:

Postby marten » Tue May 04, 2010 1:10 am

When doing my podcasts about the C-API I was surprised to see, that my Pascal-DLL was much more precise in doing an Delay(milliseconds) command, than my Smalltalk using the Delay class.

The class "Delay" under Smalltalk has a "default interrupt period" set to 100 (in Delay class>>initializeDelayedTasks, the value is stored in the class variable "InterruptPeriod").

When doing a (Delay forMilliseconds: x) wait command, you will notice, that it actual - on the average - does a: (Delay forMilliseconds: (x + InterruptPeriod)).

Therefore if you want to execute code 10 times a seconds and use (Delay forMilliseconds: 100) you will get an execution repeat rate of 5.

You may also change the Delay class>>forMilliseconds: method to:

Code: Select all
forMilliseconds: millisecondCount
  "Answer a new delay which will suspend the active process for @millisecondCount
   when sent the message wait"

  millisecondCount < 0 ifTrue: [ ExCLDTValueOutOfRange signalWith: 1].
^super new
    delayTime: ((millisecondCount - InterruptPeriod) max: 0);
    yourself
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: No registered users and 1 guest