Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
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:
rating uses 1 byte per DVD (enough for a 1-byte rating from 1 to 10).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).