Variable storage
Download
1 / 12

Variable Storage - PowerPoint PPT Presentation


  • 119 Views
  • Uploaded on

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.

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

PowerPoint Slideshow about ' Variable Storage' - cachez


An Image/Link below is provided (as is) to download presentation

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

Variable Storage

Memory Locations (Logical)

Stack

Heap

Program Code

Register

Variable Classes

Automatic (locals)

Parameters

Globals


Variable types
Variable Types

  • Scalars

  • Arrays

  • Structs

  • Unions

  • Objects ?


Row major array storage

Row Major Array Storage

char A[20][15][10];


Column major array storage

Column Major Array Storage

char A[20][15][10];


Or row major

OR (Row Major)

char A[20][15][10];


Array declaration algorithm

Array Declaration Algorithm

Dimension Node

{

int min;

int max;

int size;

}


Declaration algorithm 2
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
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
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
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
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
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


ad