120 likes | 267 Views
Variable Storage. Memory Locations (Logical) Stack Heap Program Code Register Variable Classes Automatic (locals) Parameters Globals. Variable Types. Scalars Arrays Structs Unions Objects ?. Row Major Array Storage. char A[20][15][10];. Column Major Array Storage.
E N D
Variable Storage Memory Locations (Logical) Stack Heap Program Code Register Variable Classes Automatic (locals) Parameters Globals
Variable Types • Scalars • Arrays • Structs • Unions • Objects ?
Row Major Array Storage char A[20][15][10];
Column Major Array Storage char A[20][15][10];
OR (Row Major) char A[20][15][10];
Array Declaration Algorithm Dimension Node { int min; int max; int size; }
Declaration Algorithm (2) • Doubly linked list of dimension nodes • Pass 1 – while parsing • Build linked list from left to right • Insert min, max • Size = size of an element • Append node to end of list • min = max = size = 1
Declaration Algorithm (3)Pass 2 • Traverse list from tail to head • For each node, n, going “right” to “left” • Factor = n.max – n.min + 1 • For each node, m, right to left starting with n • m.size = m.size * factor • For each node, n, going left to right • N->right->max = max; N->right->min = min • Delete first element of list
Array Declaration (Row Major) int weight[2000..2005][1..12][1..31]; list of “dimension” nodes int min, max, size size of element of this dimension 1448 124 4
Array Offset (Row Major) Traverse list summing (max-min) * size int weight[2000..2005][1..12][1..31]; x = [2002][5][31] (2002-2000) * 1448 + (5-1) * 124 + (31-1) * 4 1448 124 4
Your Turn • Assume • int A[10][20][30]; • Row major order • “Show” A’s dimension list • Show hypothetical 3-addr code for • X = A[2][3][4] ; • A[3][4][5] = 9
Your Turn 2 • Assume • int A[10][20][30]; • Column major order • “Show” A’s dimension list • Show hypothetical 3-addr code for • X = A[2][3][4] ; • A[3][4][5] = 9