[prev] 7 [next]

Dynamic Memory Allocation

So far, we have considered static memory allocation
  • all objects completely defined at compile-time
  • sizes of all objects are known to compiler
Examples:

int   x;     // 4 bytes containing a 32-bit integer value
char *cp;    // 4 bytes (on CSE machines)
             //   containing address of a char
typedef struct {float x; float y;} Point;
Point p;     // 8 bytes containing two 32-bit float values
char  s[20]; // array containing space for 20 1-byte chars