Presentation is loading. Please wait.

Presentation is loading. Please wait.

Memory organization and usage A computer’s memory is, at its lowest level, composed of binary digits (bits). The memory is organized into bytes, which.

Similar presentations


Presentation on theme: "Memory organization and usage A computer’s memory is, at its lowest level, composed of binary digits (bits). The memory is organized into bytes, which."— Presentation transcript:

1 Memory organization and usage A computer’s memory is, at its lowest level, composed of binary digits (bits). The memory is organized into bytes, which are groups of eight bits. Each byte has a unique address in memory. A byte is the smallest addressable unit of memory (i.e. nothing smaller than a byte has its own address)

2 Memory organization Table at right shows 16 bytes, each consisting of 8 bits Each byte has an address, shown in the column to the left 21380000 21380001 21380002 21380003 21380004 21380005 21380006 21380007 21380008 21380009 21380010 21380011 21380012 21380013 21380014 21380015

3 Memory organization Process BProcess AProcess C

4 Memory organization Process BProcess AProcess C STATIC SEGMENT RUNTIME STACK FREE/AVAILABLE MEMORY HEAP dynamically allocated memory

5 Memory organization STATIC SEGMENT RUNTIME STACK FREE/AVAILABLE MEMORY HEAP main(){…methodA()…} methodA(){…methodB()…} methodB() { …methodC()…} methodC(){…} main()

6 Memory organization STATIC SEGMENT RUNTIME STACK FREE/AVAILABLE MEMORY HEAP main(){…methodA()…} methodA(){…methodB()…} methodB() { …methodC()…} methodC(){…} main()methodA()

7 Memory organization STATIC SEGMENT RUNTIME STACK FREE/AVAILABLE MEMORY HEAP main(){…methodA()…} methodA(){…methodB()…} methodB() { …methodC()…} methodC(){…} main()methodA()methodB()

8 Memory organization STATIC SEGMENT RUNTIME STACK FREE/AVAILABLE MEMORY HEAP main(){…methodA()…} methodA(){…methodB()…} methodB() { …methodC()…} methodC(){…} main()methodA()methodB()methodC()

9 Memory organization STATIC SEGMENT RUNTIME STACK FREE/AVAILABLE MEMORY HEAP main(){…methodA()…} methodA(){…methodB()…} methodB() { …methodC()…} methodC(){…} main()methodA()methodB()

10 Memory organization STATIC SEGMENT RUNTIME STACK FREE/AVAILABLE MEMORY HEAP main(){…methodA()…} methodA(){…methodB()…} methodB() { …methodC()…} methodC(){…} main()methodA()

11 Memory organization STATIC SEGMENT RUNTIME STACK FREE/AVAILABLE MEMORY HEAP main(){…methodA()…} methodA(){…methodB()…} methodB() { …methodC()…} methodC(){…} main()

12 Memory organization Table at right shows 16 bytes, each consisting of 8 bits Each byte has an address, shown in the column to the left 21380000 21380001 21380002 21380003 21380004 21380005 21380006 21380007 21380008 21380009 21380010 21380011 21380012 21380013 21380014 21380015

13 Arrays A collection of variables, all of the same type. Each variable in an array is accessed by an index. An array of size n has indices from 0 to n-1. An array occupies a contiguous block of memory. The size of an array is fixed at creation time.

14 Accessing an array member t type of elements in array s size (in bytes) of an element of type t b base address of array address of element i is b + i * s

15 Array access example In Java, an int occupies 4 bytes: int [] a = new int[5]; The base address of ‘a’ is 21380002. Indices are 0, 1, 2, 3 and 4. Total size needed for array is 20 bytes (5 cells times 4 bytes per cell) 21380000 21380001 21380002 21380003 21380004 21380005 21380006 21380007 21380008 21380009 21380010 21380011 21380012 21380013 21380014 21380015 21380016 21380017 21380018 21380019 21380020 21380021 21380022

16 Array access example Where is a[0]? Address of a[0] is: b + s * i where b = 21380002, s = 4 and i = 0: 21380002 + 4 * 0 = 21380002 a[0] occupies bytes 21380002, 21380003, 21380004 and 21380005. 21380000 21380001 21380002 21380003 21380004 21380005 21380006 21380007 21380008 21380009 21380010 21380011 21380012 21380013 21380014 21380015 21380016 21380017 21380018 21380019 21380020 21380021 21380022 a[0]

17 Array access example Where is a[3]? Address of a[3] is: b + s * i where b = 21380002, s = 4 and i = 3: 21380002 + 4 * 3 = 21380014 a[3] occupies bytes 21380014, 21380015, 21380016 and 21380017. 21380000 21380001 21380002 21380003 21380004 21380005 21380006 21380007 21380008 21380009 21380010 21380011 21380012 21380013 21380014 21380015 21380016 21380017 21380018 21380019 21380020 21380021 21380022 a[3]

18 Array access example Where is a[7]? There is no such array cell, so what happens if we try to access it? In some languages (e.g. C and C++) the access is permitted, with unpredictable results. Java throws an ArrayIndexOutOfBoundsException


Download ppt "Memory organization and usage A computer’s memory is, at its lowest level, composed of binary digits (bits). The memory is organized into bytes, which."

Similar presentations


Ads by Google