0% found this document useful (0 votes)
34 views51 pages

Memory As A Programming Concept in C and C Frantisek Franek PDF Download

The document discusses the importance of memory management in C and C++ programming, highlighting that many bugs and crashes stem from memory-related issues. It aims to provide a comprehensive understanding of memory's role in programming, assuming a basic familiarity with the languages. The author, Frantisek Franek, emphasizes the need for programmers to grasp how memory affects program behavior, as this knowledge is often overlooked in traditional computer science education.

Uploaded by

inscomazieyq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views51 pages

Memory As A Programming Concept in C and C Frantisek Franek PDF Download

The document discusses the importance of memory management in C and C++ programming, highlighting that many bugs and crashes stem from memory-related issues. It aims to provide a comprehensive understanding of memory's role in programming, assuming a basic familiarity with the languages. The author, Frantisek Franek, emphasizes the need for programmers to grasp how memory affects program behavior, as this knowledge is often overlooked in traditional computer science education.

Uploaded by

inscomazieyq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Memory as a Programming Concept in C and C

Frantisek Franek download

https://ebookultra.com/download/memory-as-a-programming-concept-
in-c-and-c-frantisek-franek/

Explore and download more ebooks or textbooks


at ebookultra.com
We have selected some products that you may be interested in
Click the link to download now or visit ebookultra.com
for more options!.

Programming in C A Primer 3rd Edition E Balagurusamy

https://ebookultra.com/download/programming-in-c-a-primer-3rd-edition-
e-balagurusamy/

Programming Concepts in C 2nd Edition Robert Burns

https://ebookultra.com/download/programming-concepts-in-c-2nd-edition-
robert-burns/

Programming in C 2 e Second Edition Dey

https://ebookultra.com/download/programming-in-c-2-e-second-edition-
dey/

Functional Programming in C First Edition Ivan Cukic

https://ebookultra.com/download/functional-programming-in-c-first-
edition-ivan-cukic/
Algebraic Geometry A Volume in Memory of Paolo Francia
Mauro C. Beltrametti (Editor)

https://ebookultra.com/download/algebraic-geometry-a-volume-in-memory-
of-paolo-francia-mauro-c-beltrametti-editor/

C Programming An Introduction Rajiv Chopra

https://ebookultra.com/download/c-programming-an-introduction-rajiv-
chopra/

C Programming 5th Edition Mike Mcgrath

https://ebookultra.com/download/c-programming-5th-edition-mike-
mcgrath/

Programming C 1st Edition Jesse Liberty

https://ebookultra.com/download/programming-c-1st-edition-jesse-
liberty/

C Programming in Linux 1st edition Edition Haskins D.

https://ebookultra.com/download/c-programming-in-linux-1st-edition-
edition-haskins-d/
Memory as a Programming Concept in C and C
Frantisek Franek Digital Instant Download
Author(s): Frantisek Franek
ISBN(s): 9780521520430, 0521520436
Edition: Paperback
File Details: PDF, 1.59 MB
Year: 2003
Language: english
This page intentionally left blank
MEMORY AS A PROGRAMMING CONCEPT
IN C AND C++

The overwhelming majority of program bugs and computer crashes stem


from problems of memory access, allocation, or deallocation. Such memory-
related errors are also notoriously difficult to debug. Yet the role that memory
plays in C and C++ programming is a subject often overlooked in courses
and books because it requires specialized knowledge of operating systems,
compilers, and computer architecture in addition to a familiarity with the
languages themselves. Most professional programmers learn about memory
entirely through experience of the trouble it causes.
This book provides students and professional programmers with a concise
yet comprehensive view of the role that memory plays in all aspects of pro-
gramming and program behavior. Assuming only a basic familiarity with C
or C++, the author describes the techniques, methods, and tools available to
deal with the problems related to memory and its effective use.

Frantisek Franek is Professor of Computer Science at McMaster University,


where he helped found the Algorithms Research Group. Franek’s academic
career encompasses research in mathematics (from the well-known Balcar–
Franek theorem in Boolean algebra to finite combinatorics) as well as in com-
puter science (from algorithms on strings to artificial intelligence). The author
earned his Ph.D. at the University of Toronto and has held positions at several
universities, including the Wesley Young Researchship at Dartmouth College.
Franek has worked as a consultant on many commercial C/C++/Java projects
internationally.
MEMORY AS A
PROGRAMMING
CONCEPT IN
C AND C++

FR ANTISEK FR ANEK
McMaster University
CAMBRIDGE UNIVERSITY PRESS
Cambridge, New York, Melbourne, Madrid, Cape Town, Singapore, São Paulo, Delhi

Cambridge University Press


32 Avenue of the Americas, New York, NY 10013-2473, USA
www.cambridge.org
Information on this title: www.cambridge.org/9780521520430

© Frantisek Franek 2004

This publication is in copyright. Subject to statutory exception


and to the provisions of relevant collective licensing agreements,
no reproduction of any part may take place without the written
permission of Cambridge University Press.

First published 2004


Reprinted 2005, 2006, 2007, 2009

Printed in the United States of America

A catalog record for this publication is available from the British Library.

Library of Congress Cataloging in Publication Data


Franek, F. (Frantisek)
Memory as a programming concept in C and C++ / Frantisek Franek.
p. cm.
Includes bibliographical references and index.
ISBN 0-521-81720-X – ISBN 0-521-52043-6 (pb.)
1. Memory management (Computer science) 2. C (Computer program language)
3. C++ (Computer program language) I. Title.
QA76.9.M45F73 2003
005.4'35 – dc21 2003051543

ISBN 978-0-521-81720-2 hardback


ISBN 978-0-521-52043-0 paperback

Cambridge University Press has no responsibility for the persistence or


accuracy of URLs for external or third-party Internet Web sites referred to in
this publication and does not guarantee that any content on such Web sites is,
or will remain, accurate or appropriate. Information regarding prices, travel
timetables, and other factual information given in this work are correct at
the time of first printing, but Cambridge University Press does not guarantee
the accuracy of such information thereafter.
CONTENTS

Acknowledgments
page ix

1
Introduction
page 1

2
From Source File to Executable File
page 7
Transformation of a source file to a load (executable) module. Why
we can and do discuss source programs and their behavior as if they
were executing somewhere in memory in their source form. Concepts
of static memory allocation, dynamic memory allocation, program
address space, and program system stack.

3
Variables and Objects; Pointers and Addresses
page 21
Variables as “data containers” with names. Values as data – simple (in-
nate or elementary) data, structures, and objects. Referencing variables

v
CONTENTS

through pointers. Unnamed “data containers” and their referencing


through pointers. The dual role of pointers as address holders and bi-
nary code “interpreters”. Various interpretations of the contents of a
piece of memory. Pointer arithmetic. Why C /C++ cannot be interpreted
in a platform-free manner like Java can. Why C /C++ cannot have a
garbage collector.

4
Dynamic Allocation and Deallocation of Memory
page 45
Fundamentals of dynamic allocation and deallocation of memory: free
store (system heap); per-process memory manager; C memory allocators
malloc(), calloc(), and realloc(); and C deallocator free(). How to
handle memory allocation/deallocation errors.

5
Functions and Function Calls
page 59
System stack, activation frame, activation frame as the storage for local
auto objects and for function arguments. Passing arguments by value
as opposed to by reference. Calling sequence. Recursion and its relation
to activation frames and the system stack. The price of recursion.

6
One-Dimensional Arrays and Strings
page 81
Static one-dimensional arrays and their representation as pointers.
Array indexing as indirection. Why an array index range check cannot
be performed in C /C++. The price of run-time array index range check-
ing; the “compile-time checking” versus “run-time checking” philoso-
phies. Passing static one-dimensional arrays as function arguments.
Definition versus declaration of one-dimensional arrays. Dynamic one-
dimensional arrays. Strings as static or dynamic one-dimensional char
arrays terminated with NULL . How to add a custom-made run-time
index range checker in C++.

7
Multi-Dimensional Arrays
page 97
Static multi-dimensional arrays and their representation. Row-major
storage format and the access formula. Passing multi-dimensional
arrays as function arguments. Dynamic multi-dimensional arrays.

vi
CONTENTS

8
Classes and Objects
page 106
Basic ideas of object orientation; the concepts of classes and objects.
Operators new, new[], delete, and delete[], and related issues. Con-
structors and destructors.

9
Linked Data Structures
page 132
Fundamentals, advantages, and disadvantages of linked data struc-
tures. Moving a linked data structure in memory, or to/from a disk, or
transmitting it across a communication channel – techniques of com-
paction and serialization. Memory allocation from a specific arena.

10
Memory Leaks and Their Debugging
page 159
Classification of the causes of memory leaks. Tracing memory leaks
in C programs using location reporting and allocation/deallocation
information-gathering versions of the C allocators and deallocators.
Tracing memory leaks in C++ programs: overloading the operators new
and delete and the problems it causes. Techniques for location tracing.
Counting objects in C++. Smart pointers as a remedy for memory leaks
caused by the undetermined ownership problem.

11
Programs in Execution: Processes and Threads
page 187
Environment and environment variables, command-line arguments
and command-line argument structure. A process and its main at-
tributes – user space and process image. Spawning a new process (UNIX
fork() system call ) from the memory point of view. Principles of inter-
process communication; SystemV shared memory segments and “shared
memory leaks”. Threads and lightweight processes; advantages and dis-
advantages of threads over processes. The need to protect the “common”
data in threads. Memory leaks caused by careless multithreading.

A
Hanoi Towers Puzzle
page 210

vii
CONTENTS

B
Tracing Objects in C++
page 216

C
Tracing Objects and Memory in C++
page 227

D
Thread-Safe and Process-Safe Reporting
and Logging Functions
page 234

Glossary
page 239

Index
page 255

viii
ACKNOWLEDGMENTS

Every book is to a significant degree a team effort; there are always many
people essential for the book’s publication, from the author(s) all the way
to the editors and publisher. This book is no exception, and my sincere
gratitude goes to all the people who contributed to its publication. My
special thanks go to George Grosman, a musician and man of letters,
for his help with the style and the grammar (English is not my mother
tongue), and to Dr. Jan Holub, a postdoctoral Fellow in the Department of
Computing and Software at McMaster University, for his careful reading
of the manuscript and checking of the technical aspects of the text.

Please note that lengthier sections of code – as well as solutions to selected


exercises – can be found on my website: www.cas.mcmaster.ca/˜franek .

ix
To my parents
Prof. Dr. Jiří and Zdeňka Franěk for everything;
and my mentors and best friends
Dr. B. Balcar DrSc., Czech Academy of Sciences,
Prof. Emeritus Dr. A. Rosa, McMaster University,
Honorable V. L. Rosicky, Consul of the Czech Republic,
formerly president of Terren Corp.
for everything I know about computers and mathematics;
and my wife Marie and children Jacob and Nicole,
for their love, support, and understanding
INTRODUCTION

The motivation for this book came from years of observing computer
science students at universities as well as professional programmers work-
ing in software development. I had come to the conclusion that there
seemed to be a gap in their understanding of programming. They usu-
ally understood the syntax of the programming language they were using
and had a reasonable grasp of such topics as algorithms and data struc-
tures. However, a program is not executed in a vacuum; it is executed in
computer memory. This simple fact exerts a powerful influence on the
actual behavior of the program – or, expressed more precisely, a subtle
yet powerful influence on the semantics of the particular programming
language. I had observed that many students and programmers did not
fully understand how memory affected the behavior of the C and C++ pro-
grams they were designing. This book is an attempt to fill this gap and
provide students and programmers alike with a text that is focused on
this topic.
In a typical computer science curriculum, it is expected that students
take courses in computer architecture, operating systems, compilers, and
principles of programming languages – courses that should provide them
with a “model” of how memory matters in the behavior of programs.

1
MEMORY AS A PROGRAMMING CONCEPT

However, not all students end up taking all these courses, and even if
they do, they may not take them in the right order. Often the courses are
presented in a disjointed way, making it difficult for students to forge a
unified view of how memory affects the execution of programs. Addition-
ally, not all programmers are graduates of university or college programs
that feature a typical computer science curriculum. Whatever the reasons,
there seems to be a significant number of computer science students and
professional programmers who lack a full understanding of the intricate
relationship between programs and memory. In this book we will try to
pull together the various pieces of knowledge related to the topic from all
the fields involved (operating systems, computer architecture, compilers,
principles of programming languages, and C and C++ programming) into
a coherent picture. This should free the reader from searching various
texts for relevant information. However, in no way should this book be
viewed as a programming text, for it assumes that the reader has at least
an intermediate level of programming skills in C or C++ and hence sim-
ple programming concepts are not explained. Nor should this book be
viewed as an advanced C/C++ programming text, for it leaves too many
topics – the ones not directly related to memory – uncovered (e.g., virtual
methods and dynamic binding in C++). Moreover, it should not be seen
as an operating system book, for it does not delve into the general issues
of the discipline and only refers to facts that are relevant to C and C++
programmers.
Unfortunately, there seems to be no curriculum at any university or
college covering this topic on its own. As a result, students usually end
up with three or four disjointed views: programming syntax and (an in-
complete) C/C++ semantics; algorithms and data structures, with their
emphasis on the mathematical treatment of the subject; operating sys-
tems; and possibly compilers. Although my ambition is to fill the gaps
among these various views – at least from the perspective of C/C++ pro-
gramming – I hope that the book proves to be a valuable supplement to
any of the topics mentioned.
My own experience with software development in the real world shows
that an overwhelming number of computer program bugs and problems
are related to memory in some way. This is not so surprising, since there
are in fact few ways to “crash” a program and most involve memory. For
instance, a common problem in C/C++ is accessing an array item with
an index that is out of range (see Chapter 6). A program with such a sim-
ple bug can exhibit totally erratic behavior during different executions,

2
INTRODUCTION

behavior that ranges from perfect to incorrect, to crashing at the exe-


cution of an unrelated instruction with an unrelated message from the
operating system, to crashing at the execution of the offending instruc-
tion with a message from the operating system that signals an invalid
memory access.
With the advent of object oriented programming and the design and
development of more complex software systems, a peculiar problem has
started to manifest itself more frequently: so-called memory leaks (see
Chapter 10). In simple terms, this is a failure to design adequate house-
cleaning facilities for a program, with the result that unneeded earlier
allocated memory is not deallocated. Such undeallocated and ultimately
unused memory keeps accumulating to the point of paralyzing the exe-
cution of the program or the performance of the whole computer system.
It sounds almost mystical when a programmer’s explanation of why the
system performs so badly is “we are dealing with memory leaks”, as if
it were some kind of deficiency of the memory. A more concrete (and
accurate) explanation would be “we did not design the system properly,
so the unneeded but undeallocated memory accumulates to the point of
severely degrading the performance of the system”. The troubles that I
have witnessed in detecting and rectifying memory leaks strongly indi-
cate that many students and programmers lack a fundamental appreci-
ation of the role and function of memory in programming and program
behavior.
We are not really interested in technical, physical, or engineering char-
acteristics of memory as such (how it is organized, what the machine
word is, how the access is organized, how it is implemented on the phys-
ical level, etc.); rather, we are interested in memory as a concept and
the role it plays in programming and behavior of C/C++ programs. After
finishing this book, the reader should – in addition to recognizing super-
ficial differences in syntax and use – be able to understand (for example)
the deeper differences between the “compile-time index range checking”
philosophy used in C/C++ and the “run-time index range checking” phi-
losophy used in Pascal (Chapter 6) or between the “recursive procedure
calls” philosophy used in C/C++ and the “nonrecursive procedure calls”
philosophy used in FORTRAN (Chapter 5). As another example, the reader
of this book should come to appreciate why Java requires garbage collec-
tion whereas C/C++ does not (and in general cannot); why C/C++ can-
not be interpreted in a manner similar to Java; and why Java does not
(and cannot) have pointers whereas C/C++ does (Chapter 3) – because

3
Random documents with unrelated
content Scribd suggests to you:
so that one side of the propeller is not heavier than the other. The
shaft is pushed through the bearing tube and should project about
¼ inch beyond it. A strip of tin is wound around this projecting end
of the shaft and soldered to it in such a manner that the shaft is free
to turn in the tube.
When the plane is completely assembled try it to find the point at
which it balances when rested on the finger under the fuselage. A
hole should be punched at this point large enough to admit the iron
rod or piece of heavy wire that is to be used for the spike on which
to mount the weathervane. A second hole is punched directly above
the first one; this hole is considerably smaller than the hole beneath
it. The top of the iron spike that supports the aeroplane
weathervane is filed down to a smaller diameter so that when the
spike is pushed through the larger hole the smaller or filed part of
the spike will go through the hole in the upper part of the fuselage.
The weathervane will then rest on the shoulder formed on the spike
as shown in the illustration. A block of wood may be nailed to the
roof peak of the house or barn and a hole bored into it the size of
the supporting spike, and the spike may be pushed into this and the
aeroplane weathervane mounted on the spike. It should be well
painted in bright colors and if well made will prove a very pleasing
toy.
CHAPTER XIX
Candlesticks
WALL SCONCES, AND A LANTERN

The base of the tall candlestick shown in Fig. 94 is made of


various sized cans cut down to tray-like forms and soldered together.
As may be seen by studying them, the shafts are made from
ordinary tin campaign horns. The drip cups are made of press-in can
lids or from small cans cut down to tray-like shapes. All sharp edges
are to be turned over. The candle sockets are formed in the same
way as that of the candlestick described in Chapter VIII, page 94.
The wall sconces are made of large olive or cooking oil cans or the
cans that have contained automobile lubricating oils. All edges
should be turned or bound with folded strips of tin. Sconce No. 2
may be made of a flat sheet of tin and half of a large round can cut
down to tray size. Sconce No. 3 may be made of a large round can
cut down to shape.
PLATE XIX
A lantern made by the author

A fighting tank made by the author. The tank is made of two mackerel tins.
Parts of pepper boxes, bottle caps and a few nails used as guns
The lantern is not made from a rectangular can, but it is made
from two square pieces of tin used for the top and bottom, part of a
can being fitted in a hole cut in the square piece used for the top of
the lantern. The four corner pieces of the lantern are made of strips
of tin cut at a right angle.
Fig. 94.

A sliding door is made from a flat sheet of tin, this door sliding
between two folded strips of tin which are soldered to the
framework of the lantern. Three pieces of glass are used for the
lantern, as these are held in place by small pieces of tin folded at an
angle, one part of which rests against the glass and the other part is
soldered to the tin work of the lantern. These pieces are put in place
as each piece of glass is placed in the lantern, one at the top and
the other at the bottom of each piece of glass.
CHAPTER XX
Camp and Kitchen Equipment
A COFFEE POT—BOILING PAILS—FRYING PAN—
TOASTER—A CAMP SHOWER BATH—
CANTEEN OR HOT WATER BOTTLE—A
MATCH BOX

An excellent coffee pot may be made from a gallon can or from a


smaller one. This tin must be of the rolled rim or locked seam type
so that it will not melt apart or leak if it should accidently boil dry.
Lugs are riveted to the side of the can as described in making a
pail in Chapter IX, page 100. A series of small holes are punched in
a triangular formation in such a manner that they will be
immediately back of the spout when this is soldered in place.
The spout is made of a separate piece of tin of a triangular shape.
This piece of tin is formed into shape and is then riveted to the
coffee pot over the strainer holes. After it is held in place by the
rivets it is tightly soldered so that it will not leak. The rivets are to
prevent the spout from melting off.
A lid for the coffee pot may be made from the bottom of another
can of the same size. Some cans are provided with a cover and
these make excellent coffee pots.
Boiling or Cooking Pails.—The boiling or cooking pails are
made in the same manner as the pails described in Chapter IX, page
100. Care should be taken to use only rolled rim or locked seam pails
for any utensil that is to go over a fire.
Frying Pan.—The frying pan is made by cutting down a large
round or square can of the rolled or locked seam type. The edges
are turned and a suitable handle is riveted on as shown. Be sure to
rivet all joints that are to be subjected to the heat from a fire.
Toaster.—A toaster or broiler may be made from folded strips of
tin which are strongly riveted together as shown in Fig. 95. Be sure
to put two rivets in each corner of the toaster.
The Canteen or Hot Water Bottle.—The canteen or hot water
bottle may be made of two cake or pie tins soldered together or
from large round gallon cans cut to size and made up like a large tin
can wheel. A water-tight screw cap may be fitted to the canteen by
removing the screw top and cap from a maple syrup or automobile
oil can and soldering the screw over a suitable hole in the canteen.
Most of these screw caps may be melted off the original can by
simply heating them, the cap itself being removed during this
operation.
PLATE XX
A toy tin can kitchen made by author. The body of the range is made of a
biscuit box. The draught door is made of the top of a pepper box, with sifter top.
The ash door is made of the bottom of a pepper box. The oven door is made of
the hinged tin lid of a little cigar box. The stove lids are made of can lids. The
door handles are rivets. The range boiler is made of a long can; pipes are made
of wire. The tea kettle is made of a shoe paste box.
PLATE XXI
A doll’s bathroom made by the author.
The bath tub is made of a corn can, cut in
half lengthwise. Part of another can of the
same size is fitted with the open end of the
first can. The edges are turned over. The
washstand is made of the top and bottom
of a spice box; the bowl is made of a
varnish can cap. The column is made of a
pill box. The mirror is made of a can lid.

A tin can laundry made by the author.


The laundry tubs are made of a cigarette
box. Rivets are used as faucets. The sink is
made of a pocket tobacco box. Cup hooks
are used as faucets. The clock is made of a
small tin box and can lids.
A Camp Shower Bath.—A camp shower bath may be made of a
very large can, a shoe paste box, a short length of rubber hose and
two small flat pieces of tin.

Fig. 95.

A 5-gallon can that has contained automobile oil is easily found


and a hot lye bath will remove all traces of the oil. The lye solution is
placed in the can and raised to the boiling point. It is then poured
out and the can is rinsed with hot water.

Fig. 96.

The top of the can is removed and a strong handle fixed to the
can. A small nipple of tin is soldered to the side of the can, near the
bottom. This nipple is simply a flat piece of tin rolled into a
cylindrical shape and of a suitable size so that a piece of rubber hose
may be fitted tightly over it.
A second nipple of the same size should be made for the spray
nozzle. The spray nozzle is made from a shoe paste or salve box. A
number of fine holes are punched in the box lid and the tin pipe or
nipple is soldered in a hole made for it in the bottom of the box.
A wire hook is provided at the rim of the pail to hold the spray
nozzle in place when it is not desired to have the water run out of it.
It will be found convenient to have a double pulley and rope
rigged to hoist the pail to a convenient height after filling.
The Match Box.—The match box is made of two cigarette boxes,
one for good matches and the other for burned matches. These
boxes are of ample size to hold the paper drawer of a large box of
parlor matches.
The hinged top is left on the box that is to hold the unburned
matches. This box is soldered to two supporting brackets in such a
manner that it is held away from the piece of tin forming the back
for the two boxes and so that the lid of the upper box may be
raised. The lower box is simply soldered to the back piece. Three
folded strips of tin are soldered to the front of this second box to
form a holder for a strip of sand paper to strike the matches on.
CHAPTER XXI
Preparing the Toys for Painting
REMOVING SURPLUS SOLDER WITH SCRAPERS
—MAKING A HOE SCRAPER—PLUMBERS’
AND ROOFERS’ SCRAPERS—SCRAPING AND
FILING—BOILING THE TOYS IN A LYE BATH
—VENT HOLES

It frequently happens that more solder is applied to the joints than


is needed to cement the work together or that the solder is left in a
rather rough or lumpy state due to the inexperience of the worker.
The beginner should be in no wise discouraged if this is so, for
there is a certain knack in soldering neatly and this is only acquired
by experience and by closely observing the simple rules governing
the operation.
The beginner should be sure that enough solder is applied to hold
the work firmly together. The surplus solder may be scraped away by
using a simple scraper shaped like a hoe. An old knife is also useful
for cutting away lumps of solder. An old file or rasp which has very
coarse teeth may be used to file away solder. A finely cut file should
never be used to file solder as the fine teeth will clog up with solder
and the file be rendered useless for any further work.
Making a Hoe Scraper.—A hoe scraper may be made from a
cheap screw driver, such as those obtainable from the 5-and-10 cent
stores. The end of the screw driver that is applied to the screw is
heated red hot (a dull red). It is then placed quickly between the
jaws of a vise so that the jaws grasp it about ½ inch from the end
and before the steel has time to cool, it is bent over like a hoe, see
Fig. 97.
Use a flat fine-toothed file to file the cutting edges to about the
angle shown in the enlarged drawing of the working end of the hoe
scraper.
When the tool is filed into shape, heat the end again to a dull red
and plunge it quickly in a pail of water several times until it is
entirely cold. The tool is then ready for use.
The hoe scraper is a very simple tool to use. The cutting edge is
simply dragged with slight pressure over the solder to be removed,
and will remove a little solder each time it is dragged over it. This
tool may be sharpened easily with a smooth file or on a grindstone
when it becomes dull.
Do not try to remove too much solder at once and do not take
away too much solder from the joint as you will weaken it. Simply
smooth up the solder so that it will look well when painted over.
Plumbers’ and Roofers’ Scrapers.—Two very handy scrapers
may be purchased from a dealer in tinners’ tools. One of them is
called a Plumbers’ Scraper and is shown in Fig. 97. The other is
called a Roofing Scraper and is shown in Fig. 97. Either of these
tools will prove very useful for removing solder.
Fig. 97.

Boiling the Toys in a Lye Bath.—When the toys are completely


assembled and before they are painted they should be thoroughly
boiled up in a lye bath to remove all grease, soldering paste or acid,
paper or painted labels, etc.
The lye bath is made by adding two heaping tablespoonfuls of lye
or washing soda to the gallon of boiling water. Lye or washing soda
may be purchased at any grocery store.
The lye solution should be mixed up in an old wash boiler or a
large can or pail, placed over a hot fire and kept boiling gently
during such time as the toys are immersed in the lye bath. Enough
lye solution should be made up so that at least half of the article to
be cleaned will be covered with it. The toy is left in the bath until
that part of it which is covered with the solution is clean. It is then
removed from the bath, rinsed, and then that part of the toy that
remains to be cleaned is placed in the solution. The whole toy
should be thoroughly rinsed with warm water when it is finally
removed from the lye bath. Make sure that it is thoroughly dry and
also that any water or lye solution that may have gotten inside any
partially sealed-up parts of the toy is removed before attempting to
paint it.
Take care not to place the hands in the lye solution, hot or cold, as
it is very injurious to the skin. Any lye solution accidently spilled on
cloth will eat holes in it unless washed out with plenty of water
immediately. The work should be handled with wire hooks when
lifting it out of the lye bath.
A fresh lye bath should be made up occasionally as it loses its
cleansing power in proportion to the work boiled up in it. Lye may be
added to a bath already made up if this bath has not accumulated
too much dirt.
Vent Holes.—If a can is used to
represent a boiler or is made up
into a drum-like structure, such as
a wheel, and is not soldered up air
tight, it is apt to fill up with the hot
lye solution when placed in it.
Unless there are two air holes or
vents provided in such a boiler or
wheel, the lye or water will not all
run out when it is removed from
the bath, but it will ooze out from
time to time perhaps after the toy
has been painted for some time.
The lye thus liberated will ruin all
Fig. 98. paint with which it comes in
contact.
At least two vent holes should be punched or bored in all drum-
like structures employed about the toys, one hole at the top to admit
air and another hole at the bottom to allow the water or lye solution
to escape. These vent holes are particularly necessary in wheels that
are made from cans, see Fig. 98.
CHAPTER XXII
Notes on Painting the Toys
The tin toys should be painted with a good grade of enamel paint.
Enamel paints have varnish mixed with them and dry hard and
glossy and form a very durable and attractive finish for the toys.
There are several popular brands of these enamel paints on the
market and almost any of them will give good results if properly
applied.
Several colors should be purchased to start with, black, white,
cherry red, chrome yellow, prussian or royal blue. With this
assortment of colors, it is possible to get a variety of shades by
mixing. A can of vermilion and a can of khaki-colored enamel paint,
as well as small cans of gold and silver and bronze paint, will prove
very handy additions to the above collection of colors. The vermilion,
gold and silver paints are used to paint certain details of the toys
that need to be emphasized.
Be sure to keep all the cans of paint tightly covered when not in
use, so that the paint will not dry up and become thick and gummy
from contact with the air.
Several paint brushes should be purchased at the paint dealers,
the largest brush should be of soft hair about ½ inch wide, and the
smallest brush a tiny pointed one for detail and line work. Always
keep these brushes covered with turpentine after using them or
wash them out immediately after by scrubbing them on a cake of
soap with plenty of warm water.
Cut several small cans down to tray size and use them for mixing
the paint.
Always stir up a can of paint before using it. Use a small stick for
stirring and keep at it until the paint is thoroughly mixed. Enamel
paints may be thinned with turpentine and a bottle of this should be
kept on hand.
Do not use your paint too thick. It should be of such a consistency
as to drip slowly from the brush before the brush is wiped against
the side of the can to remove the surplus paint upon commencing
the work.
Be sure to mix up enough paint to cover the entire surface to be
painted if using mixed colors, as it is very difficult to mix a second
batch of the same shade of color.
Think how you are going to apply your paint before starting. Try to
plan your painting so that you will not have to work over a painted
surface a second time until that surface is thoroughly dry. The paint
should be applied smoothly with a brush. Just enough paint should
be held in the brush so that it flows onto the tin without streaks of
the tin showing through the paint.
Generally speaking, you should start at the top of a piece of work
and paint down. Each fresh brush stroke should overlap the one
above it and mop up any surplus paint of the former brush strokes.
Paint the intricate parts first and then the plain surfaces. For
instance, when painting the aeroplane weathervane, use a small
brush and paint the struts first, then paint around the bases and
tops of the struts on the surface of the planes. Change the small
brush for a larger one and flow more paint over the surface of the
planes, gathering up the paint around the ends of the struts as you
paint along.
When painting a large model, such as an army truck, and not
being quite sure of the quantity of paint needed, mix up enough
paint to paint all the parts of the model that show the most and
leave such parts as the bottom of the frame and the inside of the
body until last. If you have to mix up more paint for these last parts
it will not matter if it is not exactly the same shade.
If you have not had very much experience in mixing and
combining colors, it is generally better to use the different tints just
as they come from the cans, without trying to mix them.
Do not use too many colors on one toy, but try to get a pleasing
effect with two or three colors that look well together. For instance,
a truck may be painted an olive green or khaki color over its entire
surface, excepting the front of the radiator which should be painted
with silver paint.
When the first coat of paint is thoroughly dry, lines of black may
be painted about the body and various edges emphasized with
black. The hubs of the wheels, the lamps, the rim of the steering
wheel, and the filler cap on the radiator may all be painted black
with good effect. The part of the wheels which is supposed to
represent the tires should be painted a dark gray. (Gray may be
made by mixing black and white together.)
Study the large trucks seen about the streets for inspiration.
These large trucks are nearly always very simply and attractively
painted.
Real locomotives are painted black at present, but a small toy
locomotive looks much better if the wheels are painted red
(vermilion). A red band may be painted about the top of the
smokestack and the tin strips framing the cab windows should be
painted red, as may the number of the engine, etc.
The whistle should be painted with gold paint and also the inside
of the headlight, and broad lines may be painted about the boiler
with gold to represent the straps seen about locomotive boilers.
Paint the tires of the engine wheels with silver paint. The driving
rods may be painted either black or silver.
A toy locomotive thus painted will prove far more attractive to a
child than if it is painted a plain black like a real locomotive.
Generally speaking, the toys should be painted one dominating
color of an attractive tint and relieved or brightened with lines and
certain details painted with a bright or contrasting color.
Always allow one coat of paint to dry thoroughly before painting
on it again.
Tin toys may be baked in an oven when they are freshly painted.
The baking dries the enamel paint very quickly and tends to make
the paint dry very hard and smooth. The baking oven of a coal or
gas range will do very well for the baking, but be very sure that the
oven is not too hot, as a hot oven will cause the solder to melt and
the toys to fall apart. It is better to leave the oven door opened
slightly when baking the painted toys over a slow fire.
It is not necessary to bake the toys after painting as they may be
simply left to dry in the air.
Always paint slowly and carefully. Toys that are attractively painted
to match good construction are much more satisfactory than a well-
made toy poorly painted.
INDEX

A
Aeroplane weathervane, 187-191
Ambulance body, 154, 155
Anvils, 40, 41
Appliances, shop, 39-43
Ash trays, 86-93
Assembling auto truck, 139-145
Auto truck, making, 107-145
army, 153-155
axles, 114
bodies, 146-156
cabs, 165
chassis, 118-126
coal truck, 152, 153
dash board, 135-138
drilling holes in wheel centers, 113, 114
fire engine, 155, 156
fittings, 161-165
hood, 127-134
horns, 163
lights, 161-163
mud guards, 160
radiator, 125-134
soldering filler cap on radiator, 132-134
soldering seat, 138
soldering wheels to axles, 141-143
starting crank, 157, 158
steering wheel, 159
street sprinkler, 151-153
tank truck, 151
tool boxes, 163, 164
vents or louvers in hood, 130-132
washers for axles, 143-145
Auto truck wheel centers, finding, 37, 38
wheel making, 107-118
wheel, making hole in center, 112-114

B
Bench, work, 41, 42
Bending strips of tin to design, 81-83
wire in vise, 157
Biscuit cutter, 44-53
Block, punching and forming, 50
Bodies, ambulance, 154, 155
auto truck, 146-156
coal, 152
different bodies fitted to same chassis, 149-156
fire engine, 155, 156
street sprinkler, 151, 152
tank, 151
Boats, 166-175
battleship, 171, 172
ferry, 172, 173
row, 166, 167
sail, 167, 168
scow, 167
tug, 169-171
Burns, remedy for, 26
C
Cabs, truck, 165
Cabs, locomotive, 176, 177
Camp equipment, 195-199
canteen, 196
coffee pot, 195
cooking pails, 196
frying pan, 196
hot water bottle, 196
Camp equipment, match box, 199
shower bath, 196-199
toaster, 196
Candlesticks, 94-99, 192, 193
Cars, railroad, 178-181
Charcoal and wood fires for heating soldering coppers, 59, 60
Chassis, forming truck, 118-126
Cleaning and scraping tin for soldering, 71-73
cans, 21-25
Connecting rods for locomotive, 177, 178
Cooky cutters, 79-85
Cuts, remedy for, 26
Cutting away surplus tin at can rims, 101, 102
holes in tin with chisel, 96, 97
into cans, 22-24
narrow strips of tin, 80, 81
Cylinders, locomotive, 177, 178

D
Dash boards, truck, 135-138
Dividers, spring, 33
Double cutting shears, 24
Drilling hole in wheel centers, 113, 114

E
Electrical soldering coppers, 60, 67, 68

F
Filing tin, 45, 46
the soldering copper, 63-65
Fire engine, 155, 156
Fittings for truck, 161-165
Flux, applying, 74
Fluxes for soldering, 55, 62-70
Folding tin by hand, 50, 51
hatchet stake, 123-125
vise, 123
wooden roofing folder, 120-123
Forming chassis for truck, 118-126
mallet, 42, 43
using, 87-91
Forming a wire handle, 105, 106
Frying pan, 196

G
Galvanized wire, sizes, 30
used for axles, 114
Gas furnace for heating soldering coppers, 58, 59
Gasoline torch for heating soldering coppers, 58, 59

H
Handle, forming for biscuit cutter, 49-53
Hatchet stake used for folding, 123-125
Heating apparatus for soldering coppers, 55-60
soldering coppers, 65-68
Hood, truck, 127-134
Horns, truck, 163
Hot water bottle, 196

I
Ice pick used as punch, 112, 113

K
“Killed” or soldering acid, making, 68-70

L
Laying out work, 32-39
Lantern, 192, 193
Lights, truck, 161, 162
Locomotive, 174-179
boiler, 176
cab, 176
connecting rods, 177, 178
cylinders, 177, 178
fittings, 178
frame, 174-177
Locomotive wheels, 177
Lugs for pail handle, 102-105
Lye bath, description, 20
used for cleaning cans, 72, 73

M
Marking awl, 32
off work, 32, 33
line around a can, 22
Match box, 199
holder and ash tray, 91-93
Materials needed aside from cans, 30
Mechanical toys, 182-191
aeroplane weathervane, 187-191
sandmills, 182
steam turbine and boiler, 182, 183
water wheels, 182
windmill, 187
Melting off can lids, 110, 111
Metal shears, 25
Mud guards for truck, 160

N
Notes on painting the toys, 206-210

O
Oil stove used for heating soldering coppers, 56-61
P
Painting tin can toys, 206-210
Paints used for tin can toys, 206
Points to remember about soldering, 75-77
Preparing cans for toy making, 20-22
toys for painting, 200-205
Punches, 47-49
Punching a hole in tin, 46-49
Punching holes with ice pick, 112, 113
holes in radiator, 129

R
Radiator, truck, 127-134
Riveting, 100, 103-105
Rivets, 30
Running boards, truck, 160, 161

S
Sandmills, 182
Sconces, wall, 192
Scrapers, 201, 202
home-made, 201
plumbers’ and roofers’, 201, 202
Scraping away surplus solder, 200-202
Seat, truck, 138
Sheet tin, 54
Shower bath, 196-199
Smokestack for locomotive, 178
Soft solder, 54
other methods of applying, 78
Soldering, 54-70
candlestick, 99
cleaning and scraping for, 71-73
cooky cutter, 83-85
filler cap on radiator, 132-134
heating apparatus for, 55-60
hood and radiator to truck chassis, 139
“Killed Acid,” making, 68-70
narrow strips of tin, 81-83
paste, 62, 63
other methods of applying, 78
points to remember about, 75-77
practice piece, 73-78
process, 55
Soldering, scraping away surplus solder, 200-202
soft solder, 54
strips of tin to flat piece 83
wheels to axles, 141-143
copper or “iron,” 60-62
cleaning with “killed acid,” 63-67
electrical, 60, 67, 68
filing, 63-65
fitting handle to, 62
heating, 65-68
tinning, 63-68
Springs, truck, 140, 141
Squaring up a piece of tin, 34, 35
Starting crank, 157, 158
Steam turbine, 182, 183
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookultra.com

You might also like