* better
[mascara-docs.git] / lang / C / the.ansi.c.programming.language / notes.accompany.ansi.c / sx10l.html
blob0c5fd6ae522eb0b0d0037e75ee78dbf14f28eccb
1 <!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
2 <!-- This collection of hypertext pages is Copyright 1995, 1996 by Steve Summit. -->
3 <!-- This material may be freely redistributed and used -->
4 <!-- but may not be republished or sold without permission. -->
5 <html>
6 <head>
7 <link rev="owner" href="mailto:scs@eskimo.com">
8 <link rev="made" href="mailto:scs@eskimo.com">
9 <title>section 7.8.5: Storage Management</title>
10 <link href="sx10k.html" rev=precedes>
11 <link href="sx10m.html" rel=precedes>
12 <link href="sx10.html" rev=subdocument>
13 </head>
14 <body>
15 <H2>section 7.8.5: Storage Management</H2>
17 <p>The important thing to know
18 about <TT>malloc</TT> and <TT>free</TT> and friends
19 is to be careful when calling them.
20 It is easy to abuse them,
21 either by using more space than you ask for
22 (that is, writing beyond the ends of an allocated block)
23 or by continuing to use a pointer after the memory it points to has been freed
24 (perhaps because you had several pointers to the same block of memory,
25 and you forgot that when you freed one pointer
26 they all became invalid).
27 <TT>malloc</TT>-related bugs can be difficult and frustrating to track down,
28 so it's good to use programming practices
29 which help to assure that the bugs don't happen in the first place.
30 (One such practice is to make sure that pointer variables are set to
31 <TT>NULL</TT> when they don't point anywhere,
32 and to occasionally check pointer values--for instance at
33 entry to an important pointer-using function--to make sure
34 that they're not <TT>NULL</TT>.)
35 </p><p>As we mentioned on page 142 in section 6.5,
36 it is no longer necessary
37 (that is, in ANSI C)
38 to cast <TT>malloc</TT>'s value to the appropriate type,
39 though it doesn't hurt
40 to do so.
41 </p><hr>
42 <p>
43 Read sequentially:
44 <a href="sx10k.html" rev=precedes>prev</a>
45 <a href="sx10m.html" rel=precedes>next</a>
46 <a href="sx10.html" rev=subdocument>up</a>
47 <a href="top.html">top</a>
48 </p>
49 <p>
50 This page by <a href="http://www.eskimo.com/~scs/">Steve Summit</a>
51 // <a href="copyright.html">Copyright</a> 1995, 1996
52 // <a href="mailto:scs@eskimo.com">mail feedback</a>
53 </p>
54 </body>
55 </html>