Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

QBasic FAQ

How do I reduce the memory requirements of my application?? (or: How do I utilize overlays in my application??)
Posted: 14 Feb 01

CREATING OVERLAYS IN A QuickBASIC 7.x PROGRAM

If you create a very large BASIC program, you may occasionally run out of memory during execution. When this occurs, you can reduce memory requirements by using overlays. In an overlaid version of a program, specified parts of a program (known as overlays) are loaded only if and when they are needed. Overlays share the same space in memory at different times during program execution. Only code is overlaid; data is never overlaid. Programs that use overlays usually require less memory , but they run more slowly because of the time needed to load the code from disk into memory (but there is a way around this problem).

You specify overlays be enclosing overlay modules in parenthesis in the list of object files that you submit to the LINK utility. Each module in parenthesis represents one overlay. For example, the following LINK statement  produces three overlays from the seven object files A through I:

    LINK A + (B+C) + (E+F) + G + (I)

The modules (B+C), (E+F), and (I) are overlays. The remaining modules, and any pulled from the run-time libraries, constitute the memory-resident code or root of your program. Overlays are loaded into the same region of memory, so only one can be resident at a time. Duplicate names in different overlays are not supported, so each module can appear only once in a program.

You must compile each module in the program with compatible options. This means that, for example, all modules must be compiled with the same floating-point options.

If Expanded memory is present in your computer, overlays are loaded from expanded memory; otherwise, overlays are loaded from disk. (NOTE: Loading the overlays from EMS, ELIMINATES the performance hit you take when loading the overlays to disk). You can specify that overlays only be loaded from disk by linking your program with the NOEMS.OBJ stub file.

RESTRICTIONS ON OVERLAYS
 
 * Each BASIC overlay cannot be larger than 256K. There is a maximum of 64 overlays per program.
 * Overlays should not be specified as the first object module on the LINK command line (the first object module must be a part of the program that is not overlaid).
 * When you create an overlaid version of a program, make sure that each module contains in the program is compiled with compatible options
 * You cannot use the /PACKCODE option when linking an program that uses overlays.
 * You can overlay only modules to which control is transferred and returned by a standard 8086 long (32-bit) call/return instructions. Also, LINK does not produce overlay modules that can be called indirectly through function pointers. When a function is called through a pointer, the called function must be in the same overlay or root.

-=-=-=-=-=-=-=-=-

How I implemented Overlays

Previous to using overlays in my app, the program would, on a fairly regular basis, either lock up or crash due to not having enough memory. After implementing overlays I gained 75k worth of executable space to deal with (went from less that 100k free to having over 175k free). Below is the compile/link batch file I use to create the executable.


ECHO -=-=-=-=-=-=-=-=-=-
ECHO Compiling BRI5014a
bc bri5014a /fpa /fs /s;

ECHO -=-=-=-=-=-=-=-=-=-
ECHO Compiling BRI5014b
bc bri5014b /fpa /fs /s;

ECHO -=-=-=-=-=-=-=-=-=-
ECHO Compiling BRI5014c
bc bri5014c /fpa /fs /s;

ECHO -=-=-=-=-=-=-=-=-=-
ECHO Compiling BRI5014d
bc bri5014d /fpa /fs /s;

ECHO -=-=-=-=-=-=-=-=-=-
ECHO Compiling BRI5014e
bc bri5014E /fpa /fs /s;

ECHO -=-=-=-=-=-=-=-=-=-
ECHO Compiling BRIwky14
bc briwky14 /fpa /fs /s;

ECHO -=-=-=-=-=-=-=-=-=-
ECHO Compiling PINPad
bc PINPad /fpa /fs /s;

ECHO -=-=-=-=-=-=-=-=-=-
ECHO Compiling BRI5014
bc bri5014 /fpa /fs /s;

ECHO -=-=-=-=-=-=-=-=-=-
ECHO Compiling bri14lb
bc bri14lb /fpa /fs /s;

ECHO -=-=-=-=-=-=-=-=-=-
ECHO Compiling bri14lbb
bc bri14lbb /fpa /fs /s;

ECHO -=-=-=-=-=-=-=-=-=-
ECHO Compiling briprint
bc briprint /fpa /fs /s;

link /st:8192 bri5014+bri5014a+bri5014b+bri5014c+bri5014d+bri5014e+(bri14lb)+(bri14lbb)+briprint+briwky14+PINPad,,,brilib5 commbc7;


The only real problem I have discovered with using these overlays is that you cannot use a .exe compactor to reduce executable-file size. So my final .exe file went from 191k to 466k. Also, for some weird reason, if I placed too many modules into overlays, I actually lost .exe space...


(Parts of this FAQ were derived from Microsoft literature)

Back to QBasic FAQ Index
Back to QBasic Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close