Dec 182017
C Users Group magazine files for September 1994.
File CUJ0994.ZIP from The Programmer’s Corner in
Category Files from Magazines
C Users Group magazine files for September 1994.
File Name File Size Zip Size Zip Type
ALLISON 0 0 stored
AUTOCONV.C 441 218 deflated
BITSTR.CPP 536 269 deflated
BITSTR.H 521 262 deflated
BITTEST.C 387 204 deflated
CHAR1.C 268 159 deflated
CHAR2.C 284 166 deflated
CHAR3.C 280 155 deflated
CHAR4.C 278 146 deflated
DUMP.C 1517 635 deflated
GCD.C 152 94 deflated
INNAC.C 245 159 deflated
INSPECT.C 504 270 deflated
INTPROEX.C 244 150 deflated
NARROW.C 324 194 deflated
RATIONAL.CPP 625 303 deflated
RATIONAL.H 1476 338 deflated
TESTRAT.C 518 217 deflated
THREETYP.C 306 165 deflated
UNCHECK.C 379 223 deflated
FILENAME.TXT 6734 2298 deflated
HARMON 0 0 stored
FMEXT.C 9696 2822 deflated
FMEXT.DEF 394 224 deflated
FMEXT.H 536 272 deflated
FMEXT.RC 1414 633 deflated
LETTERS 0 0 stored
FORMAT.C 529 307 deflated
ZIGLER.C 3452 1055 deflated
NIEMANN 0 0 stored
TODAY.C 768 396 deflated
PLAUGER 0 0 stored
OSTREAM.H 935 242 deflated
PUGH 0 0 stored
OBJECT.C 1011 375 deflated
README.CUJ 4125 1870 deflated
ROSEN 0 0 stored
SOUNDEX.C 2214 923 deflated
SAKS 0 0 stored
GENQ4.CPP 707 329 deflated
GENQ4.H 617 304 deflated
GENQ5.CPP 478 255 deflated
GENQ5.H 771 347 deflated
GENQ5B.H 474 241 deflated
ITER.CPP 220 152 deflated
STRQ4.CPP 449 237 deflated
STRQ4.H 642 287 deflated
STRQ5.H 796 353 deflated
STRTST4.CPP 1237 518 deflated
SINGLE 0 0 stored
SINGLE2 0 0 stored
CMOSTR.CPP 10030 2842 deflated
CMOSTR.H 10076 2284 deflated
COUT.ZIP 10803 10094 deflated
FARHEAPB.CPP 5788 1631 deflated
FARHEAPB.H 2222 799 deflated
MAINTEST.CPP 4538 1479 deflated
MOBJECT.CPP 25411 5048 deflated
MOBJECT.H 2380 901 deflated
NEWTDOC.ICO 766 179 deflated
NEWTEST.CPP 3206 1367 deflated
NEWTEST.DEF 437 290 deflated
NEWTEST.H 1010 549 deflated
NEWTEST.ICO 766 155 deflated
NEWTEST.MAK 4253 1160 deflated
NEWTEST.RC 8913 2098 deflated
NEWTEST.RC2 1744 699 deflated
NEWTEST.TXT 2551 1067 deflated
NEWTEST.XLW 3465 1348 deflated
README.TXT 4608 2050 deflated
RESOURCE.H 621 304 deflated
STDAFX.CPP 204 128 deflated
STDAFX.H 404 248 deflated
FARHEAPB.CPP 5593 1618 deflated
FARHEAPB.H 2139 784 deflated
MOBJECT.CPP 13191 2968 deflated
MOBJECT.H 1588 663 deflated

Download File CUJ0994.ZIP Here

Contents of the README.TXT file

README.TXT file for NEWTEST code

Thank you for using my code. The following notes should help
you build the sample program successfully.

You should create a sub-directory RES, and move the 3 files
NEWTEST.ICO, NEWTDOC.ICO, and NEWTEST.RC2 to this sub-directory.
(If you used PKUNZIP with the option -d, this will already have
been done for you.)

You should move the file COUT.ZIP to another directory, and
PKUNZIP it there. This file contains the code and makefiles
needed to build the cout libraries that NEWTEST uses. My code
assumes that this other directory is called COUT and is located
at the same level as the directory into which you have unpacked
the NEWTEST code (NTDIR in the diagram below):

parent_directory ----|
|---- NTDIR
|---- COUT

If you use any other directory structure, you will need to edit
NEWTEST.H so that the #include references for CSTRWND.H and
WINSTRM.H are correct. You will also need to use the MSVC Project
Options menu command to ensure that MSVC correctly picks up the
reference to the COUT libraries in your particular directory


The main test routines are in maintest.cpp. I took two approaches to
testing the MemoryObject and FarHeapBlock classes. Firstly, I wanted to
use MemoryObjects for a realistic test while at the same time thrashing
the deallocation of memory. I needed to allocate a large number of
objects and then deallocate them in a different order. I therefore
implemented a simple tree-sorting routine that read a set of random
numbers in from a file and sorted them into order. I created the
sort_node class, derived from MemoryObject, for this. You will see that
it is declared as FAR. This is essential. As MemoryObjects and their
derived classes are created in Windows global memory, all pointers to
them must be far pointers. I wanted to fill a lot of FarHeapBlocks, to
exercise things properly. I therefore made each sort_node much bigger
than it would normally need to be by including an array char filler
[1000] in it.

I also decided to implement a string handling class like CString,
provided as part of MFC. Fortunately, Microsoft provide MFC source code
with Visual C++. Further, the MFC licensing conditions include the
following phrase:

Microsoft grants you a non-exclusive royalty-free right to use and
modify the source code contained in any Microsoft Foundation Classes
source code file for purposes of creating a software product. However,
you may not include this code in source form (or any modified version of
it) within any software product.

Thus, as the owner of a licensed version of Visual C++, I was able to
take the majority of the MFC code that implements CString and modify it
to work as a derived class of MemoryObject. The new class is CMOString.
The code for it is provided in the files cmostr.h and cmostr.cpp,
included within the files that you can get from CUJ to support this
article. Please remember that you should have a legal copy of MFC to
use the CMOString code and that the above licensing conditions apply to
it. (If you use the Symantec C++ compiler, you will have a legal copy

of MFC, as Symantec license MFC from Microsoft.) Microsoft has kindly
given permission for me to include the code as part of this article.

The required modifications to CString were fairly straightforward. All
pointers needed to be explicitly declared as far pointers. I had to
modify the function CString::AllocBuffer so that it used
CMemoryObject::AllocateBlock rather than the global new operator.
Similarly, I had to modify SafeDelete to use CMemoryObject::ReturnBlock
rather that the global delete operator.

The CComdtestApp::DoTest function, which does most of the testing,
deliberately does not return all of the CMemoryObjects when it exits.
This is to illustrate the handling of memory leakage. I surround the
call to DoTest with exception handling code, to trap any memory
allocation errors (such as shortage of memory) identified by the


Although I cannot guarantee support for my code, I would like
you to feel that you should ask me if you have any problems with

You can contact me via Compuserve. My address there is

My postal address is:

David Singleton
30 The Albany
Sunset Avenue
Woodford Green
United Kingdom

Good luck

David Singleton

 December 18, 2017  Add comments

Leave a Reply