If you used the TurboVision (TV) class library prior to version 1.03 (the current version), you may have noticed that your TV applications run significantly slower using version 1.03 of the library than they did before. Problems with two of the TV source filesTSCREEN.CPP and NEW.CPP in the \TVISION\SOURCE directoryare responsible for the speed problem.
You might think that knowing about these problems doesn't
do you any good. However, since Borland ships the source code
for the library along with TV, you can fix the offending files
and then update the TV.LIB file with the changes. In this article,
we'll show you how to fix and recompile these source files
from the Borland C++ 3.1 Integrated Development Environment (IDE)
for DOS, and how to re-link the new OBJ files to the TV.LIB library.
As you may know, the TV library provides its own version of the global new operator. The TV version of new works with the TV memory management system to provide a safety pool of memory for use during critical operations.
Unfortunately, the OBJ file that defines the global new operator for TV also contains debugging code. This causes any allocation of memory to first check for memory corruption (using the function heapcheck()), and then allocate 16 times the amount of memory you ask for. After allocating the memory, the debug code then sets all of the newly allocated bytes to zero.
To fix this problem, we'll open NEW.CPP from the IDE and add NDEBUG to the list of currently defined constants. To make sure the compiler can find files that appear in #include directives, we'll also add the path to the \TVISION\INCLUDE directory to the current Include Directories list. Finally, we'll recompile the NEW.CPP file with the compiler set to optimize for size and generate code for the large memory model.
Another reason applications that use TV 1.03 run slowly is that TV checks for possible video snow on some very old machines with CGA video cards. Since this type of machine is fairly obsolete, you can change the TV source code to disable snow-checking by default.
To correct this problem, we'll open TSCREEN.CPP from the IDE and change the default value of the static variable TScreen::checkSnow from True to False. After saving this change to the file, we'll recompile it with the same settings we used for the NEW.CPP file.
When we finish creating the two new OBJ files for these source files, we'll exit the IDE and invoke the command-line linker TLIB.EXE to replace the old OBJ files in the TV.LIB file with the new ones.
To keep the TV.LIB file as small as possible, we'll use the /0 option when we call TLIB from the command line. This option tells TLIB to purge comment records from the LIB file.
Now, let's use the DOS IDE to speed up the TV library.
If you want to use the command-line compiler instead of compiling
from the IDE, make the change to TSCREEN.CPP described below,
and then see Compiling TV from the command line.
Launch the DOS IDE from the TV source directory by entering
cd\borlandc\tvision\source bc
When the IDE desktop appears, choose Open... from the File menu. In the Open A File dialog box, enter NEW.CPP in the Name entry field and click the Open button.
To set the compiler options, first choose Compiler from the Options menu. In the Compiler submenu, choose Optimizations... to display the Optimization Options dialog box.
In the Optimization Options dialog box, click the Smallest Code button. Figure A shows the Optimization Options dialog box with the correct optimization settings. Click OK to save these settings.
Figure A - You'll use the Optimization Options dialog box to configure the compiler so it creates the smallest possible code.
Next, choose Compiler from the Options menu again. Choose Code Generation... from the Compiler submenu to view the Code Generation dialog box.
Select the Large radio button from the Model group to set the current memory model. Then, enter NDEBUG; in the Defines entry field to prevent the compiler from adding the debug code to the OBJ file.
When you finish, the Code Generation dialog box should resemble the one shown in Figure B. Save these settings by clicking OK.
Figure B - You'll set the memory model and global constant definitions in the Code Generation dialog box.
To set the current directory path for #include directives,
choose Directories... from the Options menu. In the Include
Directories entry field, enter
c:\borlandc\tvision\include;
at the end of the current Include Directories path. If the current path doesn't have a semicolon (;) at the end, add one before entering this path.
When you finish modifying the Include Directories path, the Directories dialog box should look like the one shown in Figure C. Click OK to save this change.
Figure C - You'll add the TVISION\INCLUDE directory to the current Include Directories path in the Directories dialog box.
Compile NEW.CPP by choosing Compile from the Compile menu. When the compiler finishes processing NEW.CPP, the status window will display the message Success : Press any key.
Press [ESC] to dismiss the status window. Choose Close from the File menu to close the window for the NEW.CPP file.
Now, choose Open... from the File menu. In the Open A File dialog box, enter TSCREEN.CPP in the Name entry field and press the Open button.
When the TSCREEN.CPP file window appears, change line 42 from
Boolean near TScreen::checkSnow = True;to
Boolean near TScreen::checkSnow = False;
To save the change to this file, choose Save from the File menu.
Since the compiler options for the NEW.CPP file are appropriate for this file too, begin compiling TSCREEN.CPP by choosing Compile from the Compile menu. When the compiler finishes processing TSCREEN.CPP, the status window will again display the message Success : Press any key.
Press [ESC] to dismiss the status window. Choose Exit from the File menu to leave the IDE.
Now that you've created NEW.OBJ and TSCREEN.OBJ, you'll
need to use the command-line librarian TLIB to merge them into
the library file. To replace the existing NEW.OBJ module in TV.LIB
with the latest version, enter
tlib /0 ..\lib\tv.lib -+new.obj
In this command, the /0 parameter tells TLIB to remove
comment records, and ..\lib\tv.lib specifies the destination
library file for TLIB's output. The input file specification,
-+new.obj, tells TLIB to look for a module with this
name and replace it with the module from the NEW.OBJ file. If
TLIB adds the module successfully, it will display
TLIB 3.02 Copyright (c) 1992 Borland International
Repeat this process for TSCREEN.OBJ by entering
tlib /0 ..\lib\tv.lib -+tscreen.obj
When TLIB returns from adding this module, the TV.LIB library
will be ready to use.
Applications built using version 1.03 of the TurboVision class
library may run much more slowly than they could. By applying
the fixes we've described here, your TV applications will
run at normal speed.
Copyright (c) 1996 The Cobb Group, a division of Ziff-Davis Publishing Company. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis Publishing Company is prohibited. The Cobb Group and The Cobb Group logo are trademarks of Ziff-Davis Publishing Company.