0% found this document useful (0 votes)
24 views1 page

Head First C Pages 5

Uploaded by

mpspsrmgk0
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)
24 views1 page

Head First C Pages 5

Uploaded by

mpspsrmgk0
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/ 1

table of contents

data structures and dynamic memory

6
Building bridges
Sometimes, a single struct is simply not enough.
To model complex data requirements, you often need to link structs together. In
this chapter, you’ll see how to use struct pointers to connect custom data types into
large, complex data structures. You’ll explore key principles by creating linked lists.
You’ll also see how to make your data structures cope with flexible amounts of data by
dynamically allocating memory on the heap, and freeing it up when you’re done. And
if good housekeeping becomes tricky, you’ll also learn how valgrind can help.

Do you need flexible storage? 268


Linked lists are like chains of data 269
Linked lists allow inserts 270
Create a recursive structure 271
Create islands in C… 272
Inserting values into the list 273
Use the heap for dynamic storage 278
Give the memory back when you’re done 279
Ask for memory with malloc()… 280
Let’s fix the code using the strdup() function 286
Free the memory when you’re done 290
An overview of the SPIES system 300
Software forensics: using valgrind 302
Use valgrind repeatedly to gather more evidence 303
Look at the evidence 304
The fix on trial 307
Your C Toolbox 309

32 bytes of
Craggy
data at location
4,204,853 on the
heap
Shutter

Isla Nublar
xvii

www.it-ebooks.info

You might also like