03_memory

03_memory - Data Structures - CSCI 102 CS102 Basic C+...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Data Structures - CSCI 102 Copyright © William C. Cheng CS102 Basic C++ Memory Management Bill Cheng http://merlot.usc.edu/cs102-s11
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
x GB of memory Memory is just as a bunch of bytes When you upgrade your laptop’s memory, what do you buy? 2 Data Structures - CSCI 102 Copyright © William C. Cheng Memory What is an integer? a floating point number? a character? They are just illusions (created by the programming language you use) Data structure is just an illusion Why do we need data structures? To organize data stored in memory Make our code easier to maintain, less bugs, etc. Some algorithms run a lot faster if the right data structures are utilized
Background image of page 2
You can talk about the variable named X , or The location of each variable’s value in memory is indexed by an address 3 Data Structures - CSCI 102 Copyright © William C. Cheng Memory Addresses You can alternately talk about the variable that lives at location 1000 int X=102; /* 0x00000066 */ 0x66 1000 memory address content at a memory address
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
You can talk about the variable named X , or The location of each variable’s value in memory is indexed by an address 4 Data Structures - CSCI 102 Copyright © William C. Cheng Memory Addresses You can alternately talk about the variable that lives at location 1000 int X=102; /* 0x00000066 */ 0x66 1000 memory address content at a memory address For int X=102; the above is the wrong picture Need 4 bytes of memory Actually, two choices
Background image of page 4
You can talk about the variable named X , or The location of each variable’s value in memory is indexed by an address 5 Data Structures - CSCI 102 Copyright © William C. Cheng Memory Addresses You can alternately talk about the variable that lives at location 1000 int X=102; /* 0x00000066 */ 0x66 1000 memory address content at a memory address Ex: Intel 0x00 1001 0x00 1002 0x00 1003 Little-endian
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
You can talk about the variable named X , or The location of each variable’s value in memory is indexed by an address 6 Data Structures - CSCI 102 Copyright © William C. Cheng Memory Addresses You can alternately talk about the variable that lives at location 1000 int X=102; /* 0x00000066 */ 0x00 1000 memory address content at a memory address Ex: Solaris, PowerPC 0x00 1001 0x00 1002 0x66 1003 Big-endian
Background image of page 6
7 Data Structures - CSCI 102 Copyright © William C. Cheng Memory Organization variables Memory Organization heap stack 0x00000000 0xffffffff 32-bit address space: Does not have to be all in one large contiguous block Use segments (code segment, data segment, stack segment) Have you heard of segmentation faults ?
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Data Structures - CSCI 102 Copyright © William C. Cheng Variables Static variable Three types of variables Stack / automatic variable Heap variable All local variables live in the stack All dynamically allocated variables live in the heap variables Memory Organization heap stack 0x00000000 0xffffffff Ex: static int x = 3; Can be inside a function or outside Ex: void foo( int y) { int z = y*y; ... } Ex:
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 32

03_memory - Data Structures - CSCI 102 CS102 Basic C+...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online