Showing posts with label Structures. Show all posts
Showing posts with label Structures. Show all posts

2008/02/05

Structures in Machine Memory

typedef struct {
  int a;
  int b;
} T;

T foo;
T bar[2];
T* h = (T*) malloc( 3* sizeof(T) );  // reserve heap space
address value offset c name region
0: ~~~~~ program
...
1000: ???? ???? 00 foo.a global variables
???? ???? 01 foo.b
1008: ???? ???? 00 bar[0].a
???? ???? 01 bar[0].b
???? ???? 02 bar[1].a
???? ???? 03 bar[1].b
1018: 0000 2000 00 h
...
2000: ???? ???? 00 h[0].a heap
???? ???? 01 h[0].b
???? ???? 02 h[1].a
???? ???? 03 h[1].b
???? ???? 04 h[2].a
???? ???? 05 h[2].b