# develop-02 9004 April 1990 — source transcripts, page 1

[Canonical transcript page](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1)

## Transcribed source material

Machine transcriptions and image descriptions; uncertain copy may be marked [illegible]. Verify against the linked originals. Historical rights remain with the original owners.

These are transcribed excerpts, not the full publications. Open the originals for remaining pages.

### Image 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1#scan-64ba496c6054d5b7935f9b6bcbfaea0ef35c2aa2306eaa1bbeffbb90d62cd238)

Transcribed text:

develop
The Apple Technical Journal

USING C++ OBJECTS IN A HANDLE-BASED WORLD

USING OBJECTS SAFELY IN OBJECT PASCAL

THE SECRET LIFE OF THE MEMORY MANAGER

SPEED YOUR SOFTWARE DEVELOPMENT WITH MACAPP

MACINTOSH Q & A

HOW TO DESIGN AN OBJECT-BASED APPLICATION

UNOFFICIAL C++ STYLE GUIDE

DEMYSTIFYING THE GS/OS CACHE

APPLE II Q & A

Issue 2 April 1990

Image description: A magazine cover with the word develop in large bold letters above a subtitle, a pink-bordered panel of hand-drawn sketches including a pencil, a fish-like diamond, a house, a bouquet of roses, a checkered tablecloth table, and a bicycle, with a list of article titles in bold capitals on the right.

Reading notes: Article titles listed in the right column were read top to bottom; the sidebar 'MACAPP' is printed in small capitals and transcribed as MACAPP. The subtitle 'The Apple Technical Journal' has wide letter spacing and was transcribed as printed.

Printed product names: develop

Printed dates: April 1990

Languages: English

[Original Image 1](https://www.vintageapple.net/files/055652c4473757dbbe78a4e2b52a8e25f1d760c6f52a799ea383a402d12821f3/668919973189a598da0c85a9.webp)

### PDF page 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1#scan-a122c79233c544c4c84a83e54f0df362b596eff44322b0325d1fc5bf5c709cd7)

Transcribed text:

d e v e l o p T h e   A p p l e   T e c h n i c a l   J o u r n a l
USING C++ OBJECTS
IN A HANDLE-BASED
WORLD
USING   OBJECTS
SAFELY IN OBJECT
PASCAL
THE SECRET LIFE
OF THE MEMORY
MANAGER
SPEED YOUR
SOFTWARE
DEVELOPMENT WITH
MACAP P
MACINTOSH Q & A
HOW TO DESIGN AN
OBJECT-BASED
APPLICATION
UNOFFICIAL C++
STYLE GUIDE
DEMYSTIFYING THE
GS/OS CACHE
APPLE II Q & A
Issu e 2   April 1990

Reading notes: Transcript is set to an empty string per the instructions because the exact text is preserved separately. Masthead letters are spaced out and used as the headline; this is uncertain. The supplied copy lists article titles, not advertised products, so productNames is empty. Issue line reads 'Issu e 2   April 1990' with a split word in the supplied copy; the date is taken as April 1990. Entries such as 'MACAP P' and 'APPLE II Q & A' show possible line-break or spacing artifacts in the supplied text. Reading order follows the supplied copy line by line and may not match the printed layout.

Printed dates: April 1990

Languages: English

[Original PDF page 1](https://www.vintageapple.net/files/026e52ae3169351a0c6703678c14506008ef18677d9a4b1eec2a77f9e80ddeab/develop-02_9004_April_1990.pdf#page=1)

### PDF page 2

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1#scan-ffebb6796d3bf82777bfa872b9010397dc0c3acdaefc57e0581d3ae1261d7116)

Transcribed text:

© 1990 Apple Computer, Inc. All rights reserved.
Apple, the Apple logo, MacApp, Macintosh, and MPW are registered trademarks of Apple
Computer, Inc.
E D I T O R I A L
Editor in Chief’s Clothing   Louella Pizzuti
Developmental Editors   Lorraine Anderson
and Carol Westberg
Editorial Assistant   Susan Marsland
Editorial Assistant   Lenore Zelony
Manager, Developer Press   David Krathwohl
A R T   &   P R O D U C T I O N
Design/Art Direction   Joss Parsey
Technical Illustration   Cleo Huggins
Production   Bruce Potterton
Printer   Craftsman Press
Film Preparation   FilmCraft
Photographer   Ralph Portillo
Circulation Management   Dee Kiamy
Online Production   Cassi Carpenter
S P E C I A L   T H A N K S
Mark Kieling
T E C H N I C A L   R E V I E W E R S
Tim Enwall   Don Loomis
Craig Prouse   John Harvey
Jon Zap   Jerry Godes
Gregg Williams   Dennis Gibbs
Jim Straus   Matt Deatherage
Andy Shebanow   Richard Clark
Larry Rosenstein   Mary Chan
Lew Rollins   Bob Campbell
Rob Neville   Jeremy Bornstein
P. Nagarajan   Rick Blair
Robin Myers   Brian Bechtel
Bob Martin   Pete Alexander
C O V E R
Illustrator   Cleo Huggins
In spite of 4 years at R.I.S.D. and 10 years of
experience (including an MS indigital
typography from Stanford), Cleo still creates.
Of course, she's got the perfect environment at
home: a parrot that talks and a boyfriend that
doesn't. If she runs into any ancient Egyptions
(and she might), she's ready with an 800-
character hieroglyphic font she created for the
Mac. Pretty cool. One thing, though: she
laughs at Louella's jokes (sometimes she even
thinks they're funny).

Reading notes: Supplied copy is an Apple Computer 1990 editorial credits page rather than an advertisement, so no advertised products or prices were found. Product names Apple, MacApp, Macintosh, and MPW appear only in the trademark notice and were not treated as advertised products. Spelling 'indigital' and 'Egyptions' and the line break '800-character' are reproduced as they appear in the supplied copy and may reflect layout hyphenation or typos. Layout, column arrangement, and spacing of the masthead could not be confirmed from the supplied copy alone.

Printed dates: 1990

Languages: English

[Original PDF page 2](https://www.vintageapple.net/files/026e52ae3169351a0c6703678c14506008ef18677d9a4b1eec2a77f9e80ddeab/develop-02_9004_April_1990.pdf#page=2)

### PDF page 3

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1#scan-ddcabb8a0399b405b70a5bab3d81a5363bb40b8d845e618aa47b4f754569d597)

Transcribed text:

Using C++ Objects in a Handle-Based World   Avoiding headaches when
you use C++ objects in the Macintosh world.   118
Using Objects Safely in Object Pascal   Guidelines to take the worry out of
using objects so you can relax and enjoy their advantages.   129
The Secret Life of the Memory Manager   Memory Manager behavior and
how it affects your applications.   140
Speed Your Software Development with MacApp   Let MacApp take care
of the user so you can focus on writing—and reusing–—code.   155
Macintosh Q & A   Questions and answers compiled by the Macintosh Developer
Technical Support group.   176
How to Design an Object-Based Application   A step-by-step two-phase
process for designing an object-bases application.   178
Unofficial C++ Style Guide   How to harness C++’s power without getting
tripped up by some of its less savory features.   204
Demystifying the GS/OS Cache   Taking the mystery and confusion out of
caching algorithms.   233
Apple II Q & A   Questions and answers compiled by the Apple II Developer
Technical Support group.   243
Index   247
Content
CONTENTS   April 1990
113

Reading notes: Headline is taken from the page-top label 'CONTENTS' and the table of contents structure is ambiguous; reading order of the title versus the contents list is uncertain.

Printed product names: MacApp · GS/OS

Printed dates: April 1990

Languages: English

[Original PDF page 3](https://www.vintageapple.net/files/026e52ae3169351a0c6703678c14506008ef18677d9a4b1eec2a77f9e80ddeab/develop-02_9004_April_1990.pdf#page=3)

### PDF page 4

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1#scan-8fb5a129036cd7262ae160c31ce7d60879c40ed2e107439df4879bcf84748b87)

Transcribed text:

Dear Readers,
Wow! Your response to the first issue of   develop   was overwhelming! You sent
almost two hundred letters and Links telling me what you liked, what you’d like
changed, and what articles you’d like to see. I’ve published (and answered) a
representative sampling in the Letters section and will continue to let you know
what happens with your suggestions. Article-specific questions are answered (by the
original authors) in the Macintosh Q & A section.
This issue of   develop   revolves around object programming. If you’ve been reading
much of what’s been coming out of Apple lately, you will have noticed quite a push
toward object programming. Apple has invested years of R & D in object
programming and we’re working to get you to take advantage of the work we’ve done.
Unless you’re already an object-based programmer, this issue probably won’t solve
any problems you’re struggling with right now. I’m hoping, however, that it helps to
convince you that object programming can save you time and effort in the long run
and that it’s worth the investment it will take to learn about a new environment.
Not only will object programming help you to write and to maintain today’s
applications, but it will also help to prepare you for tomorrow’s system software.
Providing you with code and ideas that serve you well when new products come out
is one of my top priorities, so look past today and into tomorrow and use the code
and ideas we give you.
Keep those cards and letters coming!
Louella Pizzuti
Editor
LOUELLA PIZZUTI
d e v e l o p   April 1990
114

Reading notes: Spacing around the publication name 'develop' is irregular in the extracted text, so the rendering of the title may vary.

Printed product names: develop

Printed dates: April 1990

Languages: English

[Original PDF page 4](https://www.vintageapple.net/files/026e52ae3169351a0c6703678c14506008ef18677d9a4b1eec2a77f9e80ddeab/develop-02_9004_April_1990.pdf#page=4)

### PDF page 5

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1#scan-f400a0b2258f998cf4c1faeb158b03c7688e36f57a7f261bac46dd9babf523bf)

Transcribed text:

A   a
B
b   C   c
D   d
F
G
H
I
J
K
M
N
O
P
Q
U
V
W
X
Y
Z
g
h
i
j
k
l
m
n
o
p   q
r
s
t u
v
w
x
y
z
k
h
t
i
W
B
L
E
T
T
E   R
S
t
s
Y
Z
s
o
u
q
F
Y
u
r
k
i B Z   s
t
l
X
v
Y
i
y
o
I
THE GOOD
Wow!
—Jim Russell
We just received the first issue of
develop . It is just what we need. In
fact, it couldn’t come at a better time.
Anyway, please continue to do it—we
need it! Great idea, great layout, great
topics, etc....
—Daniel Tapie
Thanks a lot for the complimentary
first issue of   develop . It makes me feel
healthy with the funny introduction of
the authors, wealthy with its luxury,
and happy for your name is nicer than
ever on the first page.
—Philippe
I believe you have a winner here!
develop   has helped me in just the first
10 minutes. I needed help with the
Palette Manager and I found it here!
Might I suggest that the CD-ROM
envelope be perforated? This would
allow easy removal of the packet and
alleviate the “now I have the CD-
ROM out, but the packet is still in the
way when I flip through the pages”
syndrome.
—Bryan Carter
Fantastic idea!!! Keep up the good
work. This first issue was FULL of
good, timely, and useful advice (code).
Thanks for your efforts to help
developers.
—Ken Duncan
Excellent magazine! I really enjoyed
the articles, source code examples,
backgrounds on the authors, etc. I
predict that   develop   will establish a
new standard of excellence in technical
support literature. But please find a
better font for the source code listings;
the font is so faint that I found myself
suffering from eye strain after a short
while.
—Ken Friedenbach
What a fantastic idea! The graphic
design in   develop   is so good that it
almost distracts from the content.
Keep up the good work and please
send the next issue (this one was
stolen…).
—Jean-Michel Karr
THE BAD
develop   has NOTHING to offer an
Apple II owner/developer. Apple no
longer has my respect as the founder of
the home computing and friendly
interfaces. I do not want a Mac and
the way I feel at this moment I would
not have a Mac if you gave it to me.
Yes, I am angry!
—R. L. Woodworth
The outstanding quality of the premier
issue of   develop   was overshadowed by
its content. It would have been
appropriate in a premier issue to
devote approximately equal space to
BOTH Apple lines of computers.
Apple II support in   develop   would
surely help Apple and encourage those
who acknowledge the IIs as very
respectable computers. May the Apple
II and Macintosh lines BOTH enjoy
continued and increasing success in
their respective markets!
—Steven Gozdziewski
L E T T E R S
LETTERS   April 1990
115 COMMENTS   We welcome timely letters to the
editor, especially from readers wishing to react to
articles that we publish in develop.   Letters should
be addressed to Louella Pizzuti; 20525 Mariani
Ave. M/S 75-3B; Cupertino, CA   95014
(AppleLink Pizzuti1).   All letters should include
name and company name as well as address
and phone number.   Letters may be excerpted or
edited for clarity and space.
SUBSCRIPTION INFORMATION   Please
address all subscription (and subscription-related)
enquiries to:
develop
Apple Computer, Inc.
P.O. Box 531
Mt. Morris, IL 61054   USA
AppleLink: DEV.SUBS

Reading notes: Scattered single letters at the start of the source appear to be a decorative or index alphabet with unclear reading order. Letter-page text includes a page header 'LETTERS April 1990' and page number 115 whose association with the body copy is uncertain.

Printed product names: develop · Palette Manager · CD-ROM · Apple II · Macintosh · Mac · AppleLink

Printed dates: April 1990

Languages: English

[Original PDF page 5](https://www.vintageapple.net/files/026e52ae3169351a0c6703678c14506008ef18677d9a4b1eec2a77f9e80ddeab/develop-02_9004_April_1990.pdf#page=5)

### PDF page 6

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1#scan-40620216ddbc0c463416834dc442d87b3517fca9ce1b47fb56c977879440be75)

Transcribed text:

A   a
B
b   C   c
D   d
F
G
H
I
J
K
M
N
O
P
Q
U
V
W
X
Y
Z
g
h
i
j
k
l
m
n
o
p   q
r
s
t u
v
w
x
y
z
k
h
t
i
W
B
L
E
T
T
E   R
S
t
s
Y
Z
s
o
u
q
F
Y
u
r
k
i B Z   s
t
l
X
v
Y
i
y
o
I
Like other commodities,   develop   is
influenced by the laws of supply and
demand. I publish articles based on what I
have and on what I believe the development
community needs. There is a definite need
for Apple II information, and   develop
will continue to be a forum in which to
meet that need, but the mix of Apple II and
Macintosh articles will continue to reflect
the mix of developers and their needs (and
available articles), rather than an absolute
50-50 balance.
—Louella
The situation on technical information
has just gotten worse with   develop .
We now have   Inside Macintosh ,
Technical Notes, the Q & A stack,
develop , and many other documents
available through APDA. All of these
have information not found anywhere
else. It is a total nightmare when I
want to find all the information on a
particular topic. I really, really,
REALLY would like ALL Macintosh
technical information in one regularly
updated reference. Get rid of all the
others.
—Tim Fredenburg
Would you settle for having all of the
pivotal information in one place (like a
CD-ROM disc, for example), and for
working toward an indexing scheme that
would let you find out all of the documents
(and pieces of sample code) that related to
your topic of interest? We believe that the
documents deserve (and need) to have lives
of their own to address the needs of the
folks who don’t want to know absolutely
everything about everything, but we also
believe that an intelligent indexer would
simplify things immensely. This issue’s
CD-ROM disc contains much of the
information you’d like to see combined,
and the next issue will have our first crack
at the intelligent indexer. All comments
and suggestions welcome.
—Louella
I’m curious to find out WHY Apple
decided to go with a CD-ROM disc. I
understand that the disc holds gobs of
data (which I would imagine goes
mostly unused every issue); however, I
wonder HOW MANY of the Mac and
Apple II developers actually own a
CD-ROM drive. Apple may be trying
to encourage developers to utilize this
technology, but at the moment it looks
like they are just flapping their wings in
the breeze. I’ve got a great idea!
Everyone who can’t use the CD-ROM
disc should mail it back to Apple. A
small, silent protest.   :-)
—Lynda
The CD-ROM gives us room to archive
all of the old issues of
develop   (which
allows us to update and to correct mistakes
every quarter), to publish code that would
never fit in our hundred-some pages, and
to explore what can be done when space is
not a problem. This issue of
develop , the
disc includes not only
develop   and all of
its associated code, but also SpInside
Macintosh (a HyperCard stack-based
version of Inside Macintosh volumes I-V),
the Macintosh Technical Notes stack, and
the Macintosh DTS Q & A stack, and of
course, the ever-popular audio track.
—Louella
THE UNCLASSIFIABLE
Egad! I received my developer’s
package this noontime and found
develop   included in the package. While
I haven’t had quite the time I wanted to
examine the material, I did notice two
serious technical errors. To whit:
d e v e l o p   April 1990
116

Reading notes: Letter-spaced and fragmentary characters in the opening alphabet block are not reliably readable as running text. Some product names are rendered with spacing artifacts and may be split or merged in the source. Reading order of the letterpress and sidebar fragments is uncertain.

Printed product names: develop · Inside Macintosh · Technical Notes · SpInside Macintosh · Macintosh Technical Notes · Macintosh DTS Q & A

Printed dates: April 1990

Languages: English

[Original PDF page 6](https://www.vintageapple.net/files/026e52ae3169351a0c6703678c14506008ef18677d9a4b1eec2a77f9e80ddeab/develop-02_9004_April_1990.pdf#page=6)

### PDF page 7

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1#scan-698f7ff66041511da332aa5592084e32af2d0a11f90ac49f5d63affee89d598c)

Transcribed text:

A   a
B
b   C   c
D   d
F
G
H
I
J
K
M
N
O
P
Q
U
V
W
X
Y
Z
g
h
i
j
k
l
m
n
o
p   q
r
s
t u
v
w
x
y
z
k
h
t
i
W
B
L
E
T
T
E   R
S
t
s
Y
Z
s
o
u
q
F
Y
u
r
k
i B Z   s
t
l
X
v
Y
i
y
o
I
1. Louella, you’ve got to be under
forty! That pale gray print for the
listings is—at least to my forty+ eyes,
well nigh invisible. Please take pity on
us old codgers and not blind us!
2. Catching penguins is far easier than
you suggest. When I was stationed at
McMurdo Sound a few decades ago,
we simply recorded the sound of the
local pod of Orcas and set up large
speakers on three sides of a square.
When we turned the recordings on,
the poor pennies thought their mortal
enemies were coming ashore and
accordingly raced out of danger—right
into our nets!
This boiled the bejabbers out of the
biologists, but made our day! Ever see
a penguin race?
—Robert Smith
I’m afraid I’m guilty on both counts: I am
under forty (although I hope the code in
this issue is easier on your eyes), and I did
not fully test all of the questions and
answers. In the future, I’ll try to convince
management that testing penguin-
catching techniques is worth the trip. I’m
sure your letter will help.
—Louella
I noticed on page 2 that two “Spirit
Guides” were listed. While trying to
figure out what these might be, I
thought of three possibilities:
continuity editors (insure that each
article adheres to a common theme);
channelers or spiritists (as in New Age,
religion, occult); or testers of wines or
vineyards. So, now that I’ve had my
guesses, could you tell me what the real
answer is and what relation they have
to your magazine? Or is it all just a
joke to see who REALLY reads your
journal?
—Rex Bontrager
Margery and Lou both contributed
immensely to actually getting
develop
into print; without the two of them, it
would probably still be a bunch of
manuscript pages sitting in my office and
I’d still be thinking that printing was the
opposite of cursive. As for the heading,
they both make me smile and so does
calling them Spirit Guides. (And it is
good to see who’s actually reading the
masthead.)
—Louella
QUESTIONS
I like   develop . It’s cool. But what’s the
deal with the code contained therein
(on CD-ROM)? Can we use it? Can
we distribute it? Both of those (at least
the first) would seem to be the intent
of   develop . But the lawyer’s funfest at
the back would seem to say otherwise.
I wondered about this before I saw the
article in MacWeek, but now I’m really
confused. Is use of code contained on
the CD-ROM as limited as seems to be
implied by the CD-ROM container’s
text? Or what?
—Robert
You can freely use, copy, and distribute the
code that’s included in
develop . Many
thanks to Teri Drenker in Apple’s software
licensing group for this issue’s revised
licensing agreement.
—Louella
LETTERS   April 1990
117

Reading notes: Large-letter alphabet block at the start is garbled and unreadable as a sequence. Reading order of letter-column fragments and some margin text is uncertain.

Printed dates: April 1990

Languages: English

[Original PDF page 7](https://www.vintageapple.net/files/026e52ae3169351a0c6703678c14506008ef18677d9a4b1eec2a77f9e80ddeab/develop-02_9004_April_1990.pdf#page=7)

### PDF page 8

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1#scan-b44f40614f198c600af3a9c75e74c6c0116fef2f16fc03f8f57ba1e4d77e5e39)

USING C++ OBJECTS IN A HANDLE-BASED WORLD

Transcribed text:

Although C++ is a powerful and flexible language, its image of the world
inside your computer was shaped by operating systems that were a bit
more “traditional” than the Macintosh’s. As a result, C++ routines that
work fine for MPW tools can cause severe problems when used in a
Macintosh application. But there are ways around these problems. This
article describes a technique that allows you to use normal C++ objects in
your Macintosh applications without undue discomfort.
Using C++ objects in the handle-based world of the Macintosh Memory Manager
can get pretty tricky at times. The Apple extension to C++ that solves the memory
allocation problems you’re bound to run into can create other headaches for you if
you need to use one or more of several important C++ features in your program. In
this article, you’ll learn about the memory allocation problems you can expect to
encounter when you create objects in C++. You’ll also learn how to get around these
problems while still retaining the use of important C++ features, by creating a
special class   PtrObject . You’ll see a sample program that uses   PtrObject , and
you’ll learn how to implement the class.
PROBLEMS WITH MEMORY ALLOCATION
FOR OBJECTS IN C++
In C++, objects are created dynamically with the   new   operator, and disposed of with
the   delete   operator when you’ve finished with them, like this:
TMyObject*   aMyObjectRef;
aMyObjectRef   =   new   TMyObject;   //   Create   a   TMyObject   object.
aMyObject->AReallyCoolRoutine();   //   Do   something   useful...
delete   aMyObject;   //   Delete   the   object.
USING C++
OBJECTS IN A
HANDLE-
BASED
WORLD
ANDY SHEBANOW
d e v e l o p   April 1990
ANDY SHEBANOW , a DTS engineer, wrote
this article for the best of reasons: “The beer
people had their say in the last issue, and it’s
about time the Mountain Dew people spoke up.”
His highly developed personal skills have earned
him the affectionate nickname “The Shebanator.”
After working for a medical imaging company,
he joined Apple twenty-odd months ago. It’s been
so long since he was outside that he’s forgotten
what his hobbies are; he vaguely remembers
something about driving cars at excessive and/or
illegal speeds.  •
118

Reading notes: Byline and sidebar text appear mixed with body copy; reading order between article and author biography may be uncertain.

Printed product names: Macintosh · MPW · Apple · C++ · Macintosh Memory Manager · PtrObject · TMyObject · Mountain Dew

Printed dates: April 1990 · twenty-odd months ago

Languages: English

[Original PDF page 8](https://www.vintageapple.net/files/026e52ae3169351a0c6703678c14506008ef18677d9a4b1eec2a77f9e80ddeab/develop-02_9004_April_1990.pdf#page=8)

### PDF page 9

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1#scan-05393b62816569cd4366de058297b98f7d2dcda8b9124292d1a94a16c859e52a)

Transcribed text:

When you use these operators, C++ transforms them into calls to   operator new   and
operator delete . The default versions of   operator new   and   operator delete
provided in the C++ library use the C Standard Library routines   malloc   and   free ,
respectively, to allocate and deallocate the memory needed to store the object.
(Actually, the   calloc   routine is called to allocate the memory, but   calloc   just turns
around and calls   malloc   to do the real work.)
These routines work fine for MPW tools, but they can cause the following severe
problems when used in a Macintosh application:
• Heap fragmentation.   Nonrelocatable memory for your objects can
be allocated in the middle of your heap, preventing the Mac’s
Memory Manager from compacting memory properly.
• Heap space permanently wasted.   Because calloc and free manage
their own list of free memory blocks and never return unused
space to the Mac’s Memory Manager, if you create a lot of C++
objects your program can run out of memory and crash even
though you have plenty of free memory available. (See the sidebar
“Everything You Didn’t Want to Know About   malloc   and   free ”
for more information on malloc internals.)
Fortunately, you can override the default versions of   operator new   and   operator
delete   in your own classes to get explicit control over memory allocation. To help
you do this, Apple extended C++ to include a predefined base class called
HandleObject . If classes you define inherit from   HandleObject , the Mac’s
NewHandle   and   DisposHandle t raps are called instead of the default   operator
new   and   operator delete   routines.
While this solves the memory problems just mentioned, it also precludes the use of
several important C++ features. Here is a partial list of the restrictions that apply
when classes you define inherit from   HandleObject :
•It is an error to declare global variables, local variables, arrays,
members, or parameters of handle-based classes (rather than
pointers to them).
• Multiple inheritance cannot be used with handle-based classes.
•Handle-based objects can be created only by the   new   operator.
The only use of a dereferenced handle-based class pointer (for
example,   *x ) is to refer to a field in the class (for example,   *x.y
or   x -> y ).
• It is not possible to allocate an array of handle-based objects—for
example,   new->MyObjects[10] .
As you can see, there are quite a few useful things you can’t do in C++ if you use
HandleObject . Most programs should be able to live with these restrictions, but   if
your program needs to use multiple inheritance or arrays of objects, a different solu-
tion is called for.
USING C++ OBJECTS IN A HANDLE-BASED WORLD   April 1990
119 Consult the MPW C++
Reference, available
from APDA as part of the MPW C++ package,
for a full list of restrictions on C++ features in
effect when classes you define inherit from
HandleObject . •

Reading notes: Monospace-style code identifiers such as operator new and malloc may have lost original formatting in extraction.

Printed dates: April 1990

Languages: English

[Original PDF page 9](https://www.vintageapple.net/files/026e52ae3169351a0c6703678c14506008ef18677d9a4b1eec2a77f9e80ddeab/develop-02_9004_April_1990.pdf#page=9)

### PDF page 10

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1#scan-0e2b68119b59011b182863ba0350fe2bd625215c3806d34a3765eecd51ed2d24)

EVERYTHING YOU DIDN’T WANT TO KNOW ABOUT MALLOC AND FREE

Transcribed text:

EVERYTHING YOU DIDN’T WANT TO KNOW
ABOUT MALLOC AND FREE
Why do the   malloc   and   free   routines wreak so much havoc in a Macintosh application? The main reason is that
these routines were originally written for UNIX systems, which have no built-in memory allocation facilities. So these
library routines ended up doing everything themselves, including free list management.
This isn’t all bad, since these routines are simpler and faster than their Macintosh Memory Manager equivalents, but
they can cause the severe problems listed earlier in this article for a Macintosh application. The worst part is that these
problems can occur even if your application doesn’t call   malloc   directly. In many situations, C++ calls   malloc   for
you, as do many of the other routines in the standard library.
Here’s how it all works (in MPW, at least):
When you request some memory from   malloc , it rounds the size up to the nearest power of 2 (8-byte minimum, ID
checked at the door). If you ask for more than 2048 bytes,   malloc   just calls   NewPtr   to allocate the memory, and
DisposPtr   to get rid of it. Otherwise,   malloc   checks its internal free list looking for blocks of the specified size. If it
doesn’t find any blocks of that size, it allocates a chunk of memory with   NewPtr   big enough to hold 2K worth of
blocks (plus 2 bytes overhead per block), and adds the new blocks to the free list for that size. It then returns you the
first block off of the free list.
When you dispose of memory with the   free   routine, it looks at the block header to determine which free list to put the
block in, and inserts it into the list (sorted by block address to allow for more intelligent freestore management in the
future). Here’s what a small free list looks like:
8-Byte Blocks
16-Byte Blocks
32-Byte Blocks
64-Byte Blocks
128-Byte Blocks
256-Byte Blocks
512-Byte Blocks
1024-Byte Blocks
2048-Byte Blocks
d e v e l o p   April 1990
120

Reading notes: Reading order of the free list diagram block labels is unclear in the extracted text.

Printed dates: April 1990

Languages: English

[Original PDF page 10](https://www.vintageapple.net/files/026e52ae3169351a0c6703678c14506008ef18677d9a4b1eec2a77f9e80ddeab/develop-02_9004_April_1990.pdf#page=10)

### PDF page 11

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/1#scan-460637d07af140619d01efd613426f7460d0e4517866f4b8894ffe47f7f1b1ed)

Transcribed text:

THE SOLUTION: CREATING A SPECIAL CLASS PTROBJECT
The solution to memory allocation problems when you can’t use   HandleObject   is
to create a special class   PtrObject   analogous to the   HandleObject   class. This class
overrides both   operator new and operator delete , so that real Memory Manager
pointers are used instead of the pointers returned by the default   operator new .
PtrObject   also supports the allocation of objects into a separate heap, which fur-
ther reduces memory fragmentation.
The method functions of the class   PtrObject   are as follows:
AllocHeap   This function creates a separate heap. All descendants of class
PtrObject   created after calling this function will use this
heap. If you do not call this function in your program, the
default (application) heap will be used.
DisposeHeap   This function disposes of the heap allocated by a previous call
to   AllocHeap . You should call this function before quitting
your application. Any   PtrObject s created inside the heap will
be invalid, so make sure that you aren’t using any of those
objects anymore (neither   operator delete   nor the destructor
for these objects will be called).
MPW (and other Mac development systems) provides versions of these routines to make life easier for people who are
porting code from UNIX systems (or MS-DOS, OS/2, etc.). However, since the   malloc   routine calls   NewPtr   rather
indiscrimately, it can cause blocks to be allocated in very inconvenient places inside your heap, and once these blocks
have been allocated, they are never disposed of.
In just one possible scenario, the user opens a large document with your program SuperOOPWrite and creates 1000
standard C++ objects (each allocated by   malloc ) to represent the elements of the document, each about 100 bytes
long.   malloc   asks   NewPtr   to create 63 blocks of memory (about 2K each), and you have about 100K less free
memory than you used to. Now the user closes the document, and you dutifully dispose of all of your objects. Guess
what? You still have 100K less memory available to you as far as the Mac’s Memory Manager is concerned, your
heap is chock full of 2K nonrelocatable blocks, and you don’t have any way to preflight memory for the next time the
user wants to open a document.
By the way, if this algorithm sounds familiar to you, it’s because the MPW code is based on a public domain version of
malloc   written by Chris Kingsley.
USING C++ OBJECTS IN A HANDLE-BASED WORLD   April 1990
121

Reading notes: Running header 'USING C++ OBJECTS IN A HANDLE-BASED WORLD' and page number '121' appear in the source text and may not be part of the primary body text.

Printed dates: April 1990

Languages: English

[Original PDF page 11](https://www.vintageapple.net/files/026e52ae3169351a0c6703678c14506008ef18677d9a4b1eec2a77f9e80ddeab/develop-02_9004_April_1990.pdf#page=11)

[Next transcribed scans](https://www.vintageapple.net/transcripts/media/va-develop-02-9004-april-1990-b9aa41/2.md)
