Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 9: Designing Your Own Data Structures > Finishing Up With Model A

Finishing Up With Model A

Back in the beginning of the chapter, we described a program that would track your DVD collection. The goal was to look at two different approaches to solving the same problem.

The first approach, model A, uses three arrays to hold a rating, title, and comment for each DVD in the collection:

#define kMaxDVDs            5000
#define kMaxTitleLength     256
#define kMaxCommentLength   256

char    rating[ kMaxDVDs ];
char    title[ kMaxDVDs ][ kMaxTitleLength ];
char    comment[ kMaxDVDs ][ kMaxCommentLength ];

Before we move on to model B, let's take a closer look at the memory used by the model A arrays:

  • The array rating uses 1 byte per DVD (enough for a 1-byte rating from 1 to 10).
  • The array title uses 256 bytes per DVD (enough for a text string holding the movie title, up to 255 bytes in length, plus the terminating byte).

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial