1 / 12

# Variable Storage - PowerPoint PPT Presentation

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.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' Variable Storage' - cachez

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Variable Storage

Memory Locations (Logical)

Stack

Heap

Program Code

Register

Variable Classes

Automatic (locals)

Parameters

Globals

• 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;

}

• 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

• 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

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

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

• 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

• 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