Skip to main content
guest
Join | Help | Sign In
Liberty BASIC Programmer's Encyc Home
guest| Join | Help | Sign In
Liberty BASIC Programmer's Encyc
  • Wiki Home
  • Recent Changes
  • Pages and Files
  • Members

Home

General Tutorials
Advanced Tutorials
GUI Programming
Graphics and Games
Strings and Text
Numbers and Math
Using Files
Windows API
Communications
Programmer's Tools

Articles by Date
FAQs
Rosetta Code
General Articles
Newsletters Contents

Table of Contents
Demos

Submit Articles
TOS and License

ScanLoop

Edit 1 …
  • 1 Tags
    • tutorials
  • Notify
  • RSS
  • Backlinks
  • Source
  • Print
  • Export (PDF)
Older Version Newer Version

Alyce Alyce Jun 17, 2011

MINIMIZE CPU USAGE IN SCAN LOOP

- DennisMcK DennisMcK

It recently came to my attention that some LB programmers were avoiding scan loops because they use 100% of the processor. Scan loops are necessary if you use WM_Liberty.dll or almost anything else that uses LB callbacks. Although the 100% usage is true there's a simple way to cure this. An api call to Sleep is all that's needed. The following two programs were tested on a PII 400 that had 27 tasks running in the background along with Liberty BASIC. As the pictures show the program without the Sleep call used 100% of the processor while the program with the sleep call used only 1%. That 1% included all of the other running tasks too.

100.gif

 '-------- 100% 
nomainwin
open "Use all of that cpu" for window as #1
#1 "trapclose [quit]"

[loop]
scan
goto [loop]

[quit]
close #1: end

1.gif

 
'-------- 1%
nomainwin
open "Minimun cpu uasage" for window as #1
#1 "trapclose [quit]"

[loop]
scan
'sleep for 50 milliseconds
calldll #kernel32,"Sleep",50 as ulong,r as void
goto [loop]

[quit]
close #1: end
Help · About · Pricing · Privacy · Terms · Support · Upgrade
Contributions to https://lbpe.wikispaces.com/ are licensed under a Custom License.
Portions not contributed by visitors are Copyright 2018 Tangient LLC
TES: The largest network of teachers in the world
Turn off "Getting Started"
  1. Home
  2. ...
Loading...