46 Pages

lecture7

Course: CS 034, Fall 2009
School: Sanford-Brown Institute
Rating:
 
 
 
 
 

Word Count: 3826

Document Preview

To CS-034 be or not to be (efficient) T. Shakespeare Doeppner P. Hugo Van Hentenryck 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 1 C/C++ versus Java Where does the time go? arrays arrays virtual methods virtual stack machine: JVM stack garbage collection Concepts garbage compiler optimizations compiler x86 architecture x86 Handles Handles 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 2 x86 architecture:...

Register Now

Unformatted Document Excerpt

Coursehero >> Georgia >> Sanford-Brown Institute >> CS 034

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
To CS-034 be or not to be (efficient) T. Shakespeare Doeppner P. Hugo Van Hentenryck 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 1 C/C++ versus Java Where does the time go? arrays arrays virtual methods virtual stack machine: JVM stack garbage collection Concepts garbage compiler optimizations compiler x86 architecture x86 Handles Handles 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 2 x86 architecture: registers Control Registers %ebp (frame ptr), %esp (stack ptr), %eis (pc) S-Registers (must be saved by subroutines) %ebx, %esi T-Registers (must not be saved by subroutines) %eax, %ecx, %edx 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 3 x86: the C Stack increasing argument n . argument 1 return address %ebp previous %ebp saved registers local variables %esp 3/16/2005 Callers frame Current frame arguments CS-034: Lecture 7 (twd/pvh: 2005) 4 x86 assembly language movel move from register/memory to register/memory move pushl/popl push and pop from the stack push addl, subl, multl, xorl, andl arithmetic expression arithmetic leal load immediate (load effective address) load jmp jump jump 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 5 x86 assembly language Conditional jumps two steps two first compare and set flags first then jump based on the flags then Function calls call: pushes %esi on the stack and jump to call: subroutine ret: pops the address on the stack and jump there ret: leave: restore %ebp and %esp leave: 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 6 Compiler Optimizations Register allocation Register Inlining Inlining Deadcode elimination Deadcode Subexpression factorization Subexpression peephole optimization peephole 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 7 Compiler Optimizations Register allocation compilers try to allocate local variables in registers compilers very useful for expressions very Not always possible no enough registers no arrays and structures arrays & may take the address of a local variable may 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 8 Compiler Optimizations Inlining compilers try to remove function calls compilers replace them with the body replace Not always possible recursion recursion size of the code size 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 9 C 2 x86 int sum(int a,int b) int sum(int a,int b) {{ return a + b; sum: return a + b; sum: pushl }} pushl movl movl movl movl movl movl popl popl addl addl ret ret %ebp push ebp %ebp push ebp %esp, %ebp ebp <- esp %esp, %ebp ebp <- esp 12(%ebp), %eax eax <- b; 12(%ebp), %eax eax <- b; 8(%ebp), %edx 8(%ebp), %edx edx <- a; edx <- a; %ebp ebp <- pop %ebp ebp <- pop %edx, %eax eax <- eax+edx %edx, %eax eax <- eax+edx return return Register allocation: where is the return address? 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 10 How to get assembly code? /Users/pvh/courses/cs034 [48] -> gcc -O2 -S fact.c /Users/pvh/courses/cs034 [48] -> gcc -O2 -S fact.c /Users/pvh/courses/cs034 [49] -> ls -l /Users/pvh/courses/cs034 [49] -> ls -l -rw-r----- 1 pvh fac 516 Mar 12 12:45 fact.s -rw-r----- 1 pvh fac 516 Mar 12 12:45 fact.s /Users/pvh/courses/cs034 [50] -> gcj -O2 -S Fact.java /Users/pvh/courses/cs034 [50] -> gcj -O2 -S Fact.java -rw-r----- 1 pvh fac 516 Mar 12 12:45 Fact.s -rw-r----- 1 pvh fac 516 Mar 12 12:45 Fact.s Native compiler for java 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 11 int sum(int a,int b) int sum(int a,int b) {{ int ss= 0; int = 0; ss= a + b; = a + b; ss+= a + s; sum: += a + s; sum: pushl %ebp return s; pushl %ebp return s; movl %esp, %ebp }} movl %esp, %ebp movl 8(%ebp), %edx movl 8(%ebp), %edx movl 12(%ebp), %ecx movl 12(%ebp), %ecx popl %ebp popl %ebp movl %edx, %eax movl %edx, %eax addl %ecx, %eax addl %ecx, %eax leal (%edx,%eax,2), %eax leal (%edx,%eax,2), %eax ret ret C 2 x86 3/16/2005 Register allocation: where is Register s? CS-034: Lecture 7 (twd/pvh: 2005) push ebp push ebp bp <- esp bp <- esp edx <- a; edx <- a; ecx <- b; ecx <- b; ebp <- pop ebp <- pop eax <- edx eax <- edx eax <- eax+ecx eax <- eax+ecx eax <- edx+2* eax eax <- edx+2* eax return return 12 C 2 x86 int sum(int a,int b) int sum(int a,int b) {{ int ss= 0; int = 0; ss= a + b; = a + b; ss+= a + s; += a + s; }} sum: sum: pushl pushl movl movl popl popl ret ret %ebp %ebp %esp, %ebp %esp, %ebp %ebp %ebp Deadcode elimination Deadcode 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 13 sum: sum: pushl %ebp pushl %ebp movl %esp, %ebp movl %esp, %ebp subl $4, %esp subl $4, %esp int sum(int a,int b) int sum(int a,int movl 16(%ebp), %eax b) movl 16(%ebp), %eax {{ addl 12(%ebp), %eax addl 12(%ebp), %eax int ss= 0; int = 0; movl %eax, -4(%ebp) movl %eax, -4(%ebp) ss= a + b; = a + b; movl -4(%ebp), %edx movl -4(%ebp), %edx ss+= a + s; += a + s; movl -4(%ebp), %eax movl -4(%ebp), %eax return s; return s; addl 12(%ebp), %eax addl 12(%ebp), %eax }} leal (%eax,%edx), %eax leal (%eax,%edx), %eax movl %eax, -4(%ebp) movl %eax, -4(%ebp) movl -4(%ebp), %eax movl -4(%ebp), %eax leave leave ret ret Java 2 x86 push ebp push ebp ebp <- esp ebp <- esp esp <- esp --4; esp <- esp 4; eax <- b eax <- b eax <- eax + a eax <- eax + a ss<- eax <- eax edx <- ss edx <eax <- ss eax <eax <- eax + a eax <- eax + a eax <- eax + edx eax <- eax + edx res <- eax res <- eax eax <- ss eax <restore esp & ebp restore esp & ebp return return 14 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) Arrays Big differences between C/C++ and Java C arrays are just pointers Java arrays objects objects bound checking bound 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 15 C 2 x86 int sum(int* a) {{ int sum(int* a) int ss= 0; int = 0; int i; int i; for(i = 0; ii< 10; ++i) for(i = 0; < 10; ++i) ss+= a[i]; += a[i]; return s; return s; }} ssum: um: pushl pushl xorl xorl movl movl movl movl xorl xorl .L6: .L6: addl addl incl incl cmpl cmpl jle jle popl popl ret ret %ebp push ebp %ebp push ebp %eax, %eax eax <- 0 %eax, %eax eax <- 0 %esp, %ebp ebp <- esp %esp, %ebp ebp <- esp 8(%ebp), %ecx ecx <- a 8(%ebp), %ecx ecx <- a %edx, %edx edx <- 0 %edx, %edx edx <- 0 (%ecx,%edx,4), %eax (%ecx,%edx,4), %eax eax <- eax + M[ecx + 4 * edx] eax <- eax + M[ecx + 4 * edx] %edx edx <- edx+1 %edx edx <- edx+1 $9, %edx $9, %edx .L6 jmp if edx <= 9 .L6 jmp if edx <= 9 %ebp ebp <- pop %ebp ebp <- pop 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 16 Arrays in C Observe no space on the stack i is register %edx s is register %eax (return value) 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 17 Java 2 x86 int sum(int[] a) {{ int sum(int[] a) int ss= 0; int = 0; int ii= 0; int = 0; for(i = 0; ii< 10; ++i) for(i = 0; < 10; ++i) ss+= a[i]; += a[i]; return s; return s; }} pushl %ebp pushl %ebp movl %esp, %ebp movl %esp, %ebp subl $24, %esp subl $24, %esp movl $0, -4(%ebp) movl $0, -4(%ebp) movl $0, -8(%ebp) movl $0, -8(%ebp) .L2: .L2: cmpl $9, -8(%ebp) cmpl $9, -8(%ebp) jle .L4 jle .L4 jmp .L7 jmp .L7 .L4: .L4: movl -4(%ebp), %eax movl -4(%ebp), %eax movl %eax, -12(%ebp) movl %eax, -12(%ebp) movl 12(%ebp), %edx movl 12(%ebp), %edx movl %edx, -16(%ebp) movl %edx, -16(%ebp) movl -8(%ebp), %ecx movl -8(%ebp), %ecx movl %ecx, -20(%ebp) movl %ecx, -20(%ebp) movl -16(%ebp), %edx movl -16(%ebp), %edx movl 8(%edx), %eax movl 8(%edx), %eax cmpl %eax, -20(%ebp) cmpl %eax, -20(%ebp) jb .L5 jb .L5 movl -20(%ebp), %ecx movl -20(%ebp), %ecx movl %ecx, (%esp) movl %ecx, (%esp) call _Jv_ThrowBadArrayIndex call _Jv_ThrowBadArrayIndex .L5: .L5: movl -12(%ebp), %eax movl -12(%ebp), %eax movl -20(%ebp), %edx movl -20(%ebp), %edx movl -16(%ebp), %ecx movl -16(%ebp), %ecx addl 12(%ecx,%edx,4), %eax addl 12(%ecx,%edx,4), %eax movl %eax, -4(%ebp) movl %eax, -4(%ebp) leal -8(%ebp), %eax leal -8(%ebp), %eax incl (%eax) incl (%eax) jmp .L2 jmp .L2 .L7: .L7: movl -4(%ebp), %eax movl -4(%ebp), %eax leave leave ret ret push ebp push ebp ebp <- esp ebp <- esp esp <- esp - 24 esp <- esp - 24 s <- 0 (stack) s <- 0 (stack) i <- 0 (stack) i <- 0 (stack) compare i and 9 compare i and 9 jump to L4 if i <= 9 jump to L4 if i <= 9 jump to L7 jump to L7 Prologue eax <- s eax <- s S[-12] <- eax (s in S[-12]) S[-12] <- eax (s in S[-12]) edx <- a edx <- a S[-16] <- edx (a in S[-16]) S[-16] <- edx (a in S[-16]) ecx <- i ecx <- i S[-20] <- ecx (i in S[-20]) S[-20] <- ecx (i in S[-20]) edx <- a edx <- a eax <- a.length eax <- a.length compare i and eax compare i and eax jump s[-20]/i < eax jump s[-20]/i < eax ecx <- i ecx <- i S[esp] <- ecx S[esp] <- ecx exception exception eax <- s eax <- s edx <- i edx <- i ecx <- a ecx <- a eax <- eax + M[exc + 4 * edx + 12] eax <- eax + M[exc + 4 * edx + 12] s <- eax; s <- eax; eax <- &i eax <- &i i <- i + 1; i <- i + 1; eax = s; eax = s; Checks Access 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 18 Java 2 x86 pushl %ebp push ebp pushl %ebp push ebp movl %esp, %ebp movl %esp, %ebp ebp <- esp ebp <- esp subl $24, %esp esp <- esp --24 subl $24, %esp esp <- esp 24 movl $0, -4(%ebp) ss<- 0 (stack) movl $0, -4(%ebp) <- 0 (stack) movl $0, -8(%ebp) ii<- 0 (stack) movl $0, -8(%ebp) <- 0 (stack) .L2: .L2: cmpl $9, -8(%ebp) cmpl $9, -8(%ebp) jle .L4 L4 if ii<= 9 jle .L4 L4 if <= 9 jmp .L7 jump to L7 jmp .L7 jump to L7 .L4 .L4 . . .L7: .L7: movl -4(%ebp), %eax eax = s; movl -4(%ebp), %eax eax = s; leave leave ret ret CS-034: Lecture 7 (twd/pvh: 2005) stack space! 3/16/2005 19 Java 2 x86 .L4: .L4: movl -4(%ebp), %eax movl -4(%ebp), %eax movl %eax, -12(%ebp) movl %eax, -12(%ebp) movl 12(%ebp), %edx movl 12(%ebp), %edx movl %edx, -16(%ebp) movl %edx, -16(%ebp) movl -8(%ebp), %ecx movl -8(%ebp), %ecx movl %ecx, -20(%ebp) movl %ecx, -20(%ebp) movl -16(%ebp), %edx movl -16(%ebp), %edx movl 8(%edx), %eax movl 8(%edx), %eax cmpl %eax, -20(%ebp) cmpl %eax, -20(%ebp) jb .L5 jb .L5 movl -20(%ebp), %ecx movl -20(%ebp), %ecx movl %ecx, (%esp) movl %ecx, (%esp) call _Jv_ThrowBadArrayIndex call _Jv_ThrowBadArrayIndex 3/16/2005 eax <- ss eax <S[-12] <- eax (s in S[-12]) S[-12] <- eax (s in S[-12]) edx <- a edx <- a S[-16] <- edx (a in S[-16]) S[-16] <- edx (a in S[-16]) ecx <- ii ecx <S[-20] <- ecx (i in S[-20]) S[-20] <- ecx (i in S[-20]) edx <- a edx <- a eax <- a.length eax <- a.length compare iiand eax compare and eax jump s[-20]/i < eax jump s[-20]/i < eax ecx <- ii ecx <S[esp] <- ecx S[esp] <- ecx exception exception 20 CS-034: Lecture 7 (twd/pvh: 2005) Java 2 x86 .L4: .L4: movl movl movl movl -16(%ebp), %edx -16(%ebp), %edx 8(%edx), %eax 8(%edx), %eax edx <- a edx <- a eax <- a.length eax <- a.length The array in Java is an object! 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 21 Java 2 x86 .L5: .L5: movl -12(%ebp), %eax eax <- ss movl -12(%ebp), %eax eax <movl -20(%ebp), %edx edx <- ii movl -20(%ebp), %edx edx <movl -16(%ebp), %ecx ecx <- a movl -16(%ebp), %ecx ecx <- a addl 12(%ecx,%edx,4), addl %eax 12(%ecx,%edx,4), %eax eax<-eax+M[exc+4*edx+12] eax<-eax+M[exc+4*edx+12] movl %eax, -4(%ebp) ss<- eax; movl %eax, -4(%ebp) <- eax; leal -8(%ebp), %eax eax <- &i leal -8(%ebp), %eax eax <- &i incl (%eax) ii<- ii+ 1; incl (%eax) <- + 1; jmp .L2 jmp .L2 What the $#$$% is this 12? 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 22 Arrays Big differences in efficiency between C/C++ and Java between C arrays are just pointers Java arrays objects objects bound checking bound 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 23 More on Arrays in Java class Foo {{int get() {{return 3; }} class Foo int get() return 3; }} class Bar extends Foo {{int get() {{return 6;}} class Bar extends Foo int get() return 6;}} public class Array {{ public class Array public static void main(String[] args) {{ public static void main(String[] args) Bar[] a = new Bar[10]; Bar[] a = new Bar[10]; Foo[] b = a; Foo[] b = a; b[3] = new Foo(); b[3] = new Foo(); System.out.println(b[3].get()); System.out.println(b[3].get()); }} }} Java compiles this program! 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 24 More on Arrays in Java movl %ebx, 4(%esp) movl %ebx, 4(%esp) movl %esi, (%esp) movl %esi, (%esp) call _Jv_CheckArrayStore call _Jv_CheckArrayStore cmpb $0, -9(%ebp) cmpb $0, -9(%ebp) movl %ebx, 24(%esi) movl %ebx, 24(%esi) je .L8 je .L8 Every store in an array has a runtime check! 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 25 C 2 x86 class Stack {{ class Stack int a[100]; int a[100]; int top; int top; public: public: Stack() ::top(-1) {} Stack() top(-1) {} void push(int i) {{a[++top] = i; }} void push(int i) a[++top] = i; int pop() {{return a[top--]; }} int pop() return a[top--]; }; }; void g(Stack* s) {{ void g(Stack* s) int ii= 0; int = 0; while (i < 10) while (i < 10) s->push(i++); s->push(i++); }} How is g compiled? 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 26 pushl %ebp pushl %ebp xorl %ecx, %ecx xorl %ecx, %ecx movl %esp, %ebp movl %esp, %ebp pushl %ebx pushl %ebx movl 8(%ebp), %ebx movl 8(%ebp), %ebx movl 400(%ebx), %edx movl 400(%ebx), %edx .L6: .L6: movl %ecx, %eax movl %ecx, %eax incl %edx incl %edx incl %ecx incl %ecx movl %eax, (%ebx,%edx,4) movl %eax, (%ebx,%edx,4) cmpl $9, %ecx cmpl $9, %ecx jle .L6 jle .L6 movl %edx, 400(%ebx) movl %edx, 400(%ebx) popl %ebx popl %ebx popl %ebp popl %ebp ret ret 3/16/2005 ecx <- 0 C 2 x86ecx <- 0esp ebp <- Why two incl? push ebp push ebp ebp <- esp push ebx (save ebx) push ebx (save ebx) ebx <- ss ebx <edx <- top edx <- top eax <- ecx/i eax <- ecx/i edx <- edx + 1 edx <- edx + 1 ecx <- ecx + 1 ecx <- ecx + 1 eax/i -> S[ebx+4*edx/top] eax/i -> S[ebx+4*edx/top] jump if ecx/i <= 9 jump if ecx/i <= 9 top <- edx; top <- edx; ebx <- pop (restore ebx) ebx <- pop (restore ebx) ebp <- pop ebp <- pop CS-034: Lecture 7 (twd/pvh: 2005) 27 Compiler Optimizations Inlining compilers remove function calls compilers replace them with the body of the function replace The call to push is removed direct manipulation of the stack direct top: offset 400 top: 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 28 C 2 x86 class Stack {{ class Stack int a[100]; int a[100]; int top; int top; public: public: Stack() ::top(-1) {} Stack() top(-1) {} virtual void push(int i) {{a[++top] = i; }} virtual void push(int i) a[++top] = i; int pop() {{return a[top--]; }} int pop() return a[top--]; }; }; 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 29 Stack VTBL push VTBL of Stack a[0] a[99] top 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 30 pushl %ebp pushl %ebp movl %esp, %ebp movl %esp, %ebp pushl %esi pushl %esi pushl %ebx pushl %ebx subl $16, %esp subl $16, %esp xorl %ebx, %ebx xorl %ebx, %ebx movl 8(%ebp), %esi movl 8(%ebp), %esi .L5: .L5: movl (%esi), %eax movl (%esi), %eax movl %ebx, 4(%esp) movl %ebx, 4(%esp) incl %ebx incl %ebx movl %esi, (%esp) movl %esi, (%esp) call *(%eax) call *(%eax) cmpl $9, %ebx cmpl $9, %ebx jle .L5 jle .L5 addl $16, %esp addl $16, %esp popl %ebx popl %ebx popl %esi popl %esi popl %ebp popl %ebp ret ret 3/16/2005 C 2 x86 No inlining! push ebp push ebp ebp <- esp ebp <- esp push esi push esi push ebx push ebx eps <- eps --16 eps <- eps 16 ebx <- 0 ebx <- 0 esi <- &s esi <- &s eax <- *(&s) [vtbl] eax <- *(&s) [vtbl] S[4] <- ebx/i S[4] <- ebx/i ebx <- ebx + 1; ebx <- ebx + 1; S[0] <- esi/s S[0] <- esi/s call the routine stored in %eax call the routine stored in %eax compare ebx and $9 compare ebx and $9 jump jump restore the stack restore the stack restore ebx restore ebx restore esi restore esi restore ebp restore ebp 31 CS-034: Lecture 7 (twd/pvh: 2005) pushl %ebp push ebp pushl %ebp push ebp movl %esp, %ebp ebp <- esp movl %esp, %ebp ebp <- esp pushl %esi push esi pushl %esi push esi pushl %ebx push ebx pushl %ebx push ebx subl $16, %esp eps <- eps --16 subl $16, %esp eps <- eps 16 xorl %ebx, %ebx ebx <- 00 xorl %ebx, %ebx ebx <movl 8(%ebp), %esi esi <- &s movl 8(%ebp), %esi esi <- &s .L5: .L5: movl (%esi), %eax eax <- *(&s) [vtbl] movl (%esi), %eax eax <- *(&s) [vtbl] movl %ebx, 4(%esp) S[4] <- ebx/i movl %ebx, 4(%esp) S[4] <- ebx/i incl %ebx ebx <- ebx + 1; incl %ebx ebx <- ebx + 1; movl %esi, (%esp) S[0] <- esi/s movl %esi, (%esp) S[0] <- esi/s call *(%eax) call the routine stored in %eax call *(%eax) call the routine stored in %eax cmpl $9, %ebx compare ebx and $9 cmpl $9, %ebx compare ebx and $9 jle .L5 jump jle .L5 jump addl $16, %esp restore the stack addl $16, %esp restore the stack popl %ebx restore ebx popl %ebx restore ebx popl %esi restore esi popl %esi restore esi popl %ebp restore ebp popl %ebp restore ebp ret 3/16/2005 CS-034: Lecture 7 (twd/pvh: 2005) 32 ret C 2 x86 C 2 x86 push: push: pushl pushl movl movl movl movl movl movl movl movl incl incl movl movl movl movl popl popl ret ret 3/16/2005 why the 4? %ebp %ebp %esp, %ebp %esp, %ebp 8(%ebp), %eax 8(%ebp), %eax 12(%ebp), %edx 12(%ebp), %edx 404(%eax), %ecx 404(%eax), %ecx %ecx %ecx %ecx, 404(%eax) %ecx, 404(%eax) %edx, 4(%eax,%ecx,4) %edx, 4(%eax,%ecx,4) %ebp %ebp eax <- &s eax <- &s edx <- ii edx <ecx <- top; ecx <- top; ecx++; ecx++; top <- ecx top <- ecx a[4*ecx] <- ii a[4*ecx] <- CS-034: Lecture 7 (twd/pvh: 2005) 33 void swap(int& a,int& b) void swap(int& a,int& b) {{ where is tmp? int tmp = a; int tmp = a; a = b; a = b; swap swap b = tmp; b = tmp; pushl %ebp push ebp pushl %ebp push ebp }} movl %esp, %ebp ebp <- esp movl %esp, %ebp ebp <- esp movl 8(%ebp), %edx edx <- &am...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Sanford-Brown Institute - CS - 034
CS34 Lecture 8CS-034 Its Magic Thomas Doeppner Pascal Van Hentenryck3/23/2005CS-034: Lecture 8 (twd/pvh: 2005)1Storagestack Local Variablesdynamic data textmalloc and new everything else Code3/23/2005CS-034: Lecture 8 (twd/pvh: 2
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab1a.dvi %Pages: 7 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMSY10 CMTT12 CMTT10 CMR8 %+ CMR6 CMR9 CMTT9 CMTI10 %EndCo
Sanford-Brown Institute - CS - 034
CS034Intro to Systems ProgrammingDoeppner &amp; Van HentenryckLab 1.1Out: February 2, 2005 What youll learn.In this lab, you will write and compile your rst C program, all from scratch. Well go through step by step what is required to write a com
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab1b.dvi %Pages: 3 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMTT12 CMTT10 CMR8 CMR6 CMR9 %+ CMTT9 CMSY10 %EndComments
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab2a.dvi %Pages: 8 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMTT10 CMSY10 CMMI10 CMMI8 %+ CMR8 CMR6 CMR9 CMTT9 %EndCom
Sanford-Brown Institute - CS - 034
CS034Intro to Systems ProgrammingDoeppner &amp; Van HentenryckLab 2.1Out: 9 February 2005 What youll learn.In the rst part of this lab, you will practice using bitwise operators. In the second part, you will open an image and read formatted data
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab2b.dvi %Pages: 6 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMTT10 CMSY10 CMTI10 %EndComments %DVIPSWebPage: (www.radi
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab3a.dvi %Pages: 3 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMTT10 CMTI10 %EndComments %DVIPSWebPage: (www.radicaleye.
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab3b.dvi %Pages: 2 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMR8 CMTT10 CMR6 CMR9 %EndComments %DVIPSWebPage: (www.rad
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab4.2.dvi %Pages: 5 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMTT10 CMMI10 CMR8 CMR6 CMR9 %EndComments %DVIPSWebPage:
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab5-1.dvi %Pages: 5 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMTT10 CMTT12 CMR8 CMR6 CMR9 %EndComments %DVIPSWebPage:
SUNY Stony Brook - MAT - 125
MAT125.R92: QUIZ 6SOLUTIONSName: Using linear approximation, estimate3 8.1. (Hint: 3 8.1 = f (8.1), where f (x) = 3 x.) f (x) f (a) + f (a)(x a) for a close to x. Specically, f (8.1) = f (8) + f (8)(8.1 8) (we choose a = 8 because its close t
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab5-2.dvi %Pages: 3 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMTT10 %EndComments %DVIPSWebPage: (www.radicaleye.com) %
Sanford-Brown Institute - CS - 034
CS034Intro to Systems ProgrammingDoeppner &amp; Van HentenryckLab 5.2Out: Thursday, March 3rd, 2005 What youll learn.In this lab, you will learn how to subclass in C+ and how to override methods.How youll do it.You will subclass from your Imag
SUNY Stony Brook - MAT - 125
MAT125.R92: QUIZ 2SOLUTIONS2x + 5 . Find the inverse function of f (x). x3 2x + 5 The function f (x) is given by the equation y = . We need to solve x3 for x: 2x + 5 y= x3 (x 3)y = 2x + 5 xy 3y = 2x + 5 xy 2x = 5 + 3y (y 2)x = 3y + 5 3y + 5 x=
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab6.dvi %Pages: 6 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMTT10 CMTT12 CMSY10 %EndComments %DVIPSWebPage: (www.radic
Sanford-Brown Institute - CS - 034
CS034Intro to Systems ProgrammingDoeppner &amp; Van HentenryckLab 6Out: Wednesday 9 March 2005 What youll learn.Modern C+ comes with a powerful template library, the Standard Template Library, or STL. The STL is based on the independent concepts
SUNY Stony Brook - MAT - 125
MAT125.R91: QUIZ 5SOLUTIONS3x + 1 . Evaluate the following limits: x3 3x + 1 (a) lim f (x) = lim . x3+ x3+ x 3 When x approaches 3 from the right, 3x + 1 is close to 3(3) + 1 = 10 and x 3 is a small positive number. 3x + 1 is 10 divided by a sma
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab7a.dvi %Pages: 4 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMTT10 CMTT12 CMMI10 CMSY10 %EndComments %DVIPSWebPage: (w
SUNY Stony Brook - MAT - 125
MAT 125: MIDTERM I PRACTICESOLUTIONSChapter 1 2. (a) g(2) = 3 (b) passes horizontal line test (c) g1 0.2 (d) (1, 3.5), same as range of g(x) (e)15. domain: 4 3x2 0 4 3x2 4 or x2 3 22 , 33 range: from 0 to 4 3 0 2; [0, 2] 6. domain:
SUNY Stony Brook - MAT - 125
MAT125.R91: QUIZ 2SOLUTIONS Let f (x) = 2 x2 + 5, x 0. Find the inverse function of f (x). The function f (x) is given by the equation y = 2 x2 + 5. We need to solve for x: y = 2 x2 + 5 y 2 = x +5 2 y2 = x2 + 5 2 y2 5 = x2 2 y2 5 x= 2 y2 Hence
SUNY Stony Brook - MAT - 125
MAT125.R91: QUIZ 9SOLUTIONSFind the absolute maximum and absolute minimum values of f (x) = x4 2x2 + 3 on the interval [1, 1]. f (x) = (x4 2x2 + 3) = 4x3 4x Critical points: The derivative exists everywhere, so we only need to check where it is
SUNY Stony Brook - MAT - 125
MAT125.R92: QUIZ 0SOLUTIONSNo score will be assigned for this quiz. The graph of the function f (x) is given below:11(a) Determine the domain and range of f (x). Domain: 4 &lt; x &lt; 1 and 1 &lt; x &lt; 4 (or, in other notations, (4, 1) and (1, 4). We
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab7b.dvi %Pages: 3 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMSY10 CMMI12 CMTT10 %EndComments %DVIPSWebPage: (www.radi
Sanford-Brown Institute - CS - 034
%!PS-Adobe-2.0 %Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software %Title: lab8b.dvi %Pages: 5 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX10 CMR10 CMBX12 CMTI12 CMTT10 CMSY10 CMMI10 CMTI10 %EndComments %DVIPSWebPage: (w
USC - CSCI - 577
Team Number: Week: Program Size (SLOC) Base Added Deleted Modified Reused # of COTS Total New SLOC Effort (Hours) Project Mgmt. Requirements COTS Assessment Design Life Cycle Planning Configuration Mgmt. Feasibility Analysis Code COTS Tailoring COTS
USC - CSCI - 577
Team Number: Week: Program Size (SLOC) Base Added Deleted Modified Reused # of COTS Total New SLOC Effort (Hours) Project Mgmt. Requirements COTS Assessment Design Life Cycle Planning Configuration Mgmt. Feasibility Analysis Code COTS Tailoring COTS
USC - CSCI - 577
Team Number: Week: Program Size (SLOC) Base Added Deleted Modified Reused # of COTS Total New SLOC Effort (Hours) Project Mgmt. Requirements COTS Assessment Design Life Cycle Planning Configuration Mgmt. Feasibility Analysis Code COTS Tailoring COTS
USC - CSCI - 577
Team Number: Week: Program Size (SLOC) Base Added Deleted Modified Reused # of COTS Total New SLOC Effort (Hours) Project Mgmt. Requirements COTS Assessment Design Life Cycle Planning Configuration Mgmt. Feasibility Analysis Code COTS Tailoring COTS
USC - CSCI - 577
Team Number: Week: Program Size (SLOC) Base Added Deleted Modified Reused # of COTS Total New SLOC Effort (Hours) Project Mgmt. Requirements COTS Assessment Design Life Cycle Planning Configuration Mgmt. Feasibility Analysis Code COTS Tailoring COTS
USC - CSCI - 577
Team Number: Week: Program Size (SLOC) Base Added Deleted Modified Reused # of COTS Total New SLOC Effort (Hours) Project Mgmt. Requirements COTS Assessment Design Life Cycle Planning Configuration Mgmt. Feasibility Analysis Code COTS Tailoring COTS
USC - CSCI - 577
Team Number: Week: Program Size (SLOC) Base Added Deleted Modified Reused # of COTS Total New SLOC Effort (Hours) Project Mgmt. Requirements COTS Assessment Design Life Cycle Planning Configuration Mgmt. Feasibility Analysis Code COTS Tailoring COTS
USC - CSCI - 577
Team Number: Week: Program Size (SLOC) Base Added Deleted Modified Reused # of COTS Total New SLOC Effort (Hours) Project Mgmt. Requirements COTS Assessment Design Life Cycle Planning Configuration Mgmt. Feasibility Analysis Code COTS Tailoring COTS
USC - CSCI - 577
Team Number: Week: Program Size (SLOC) Base Added Deleted Modified Reused # of COTS Total New SLOC Effort (Hours) Project Mgmt. Requirements COTS Assessment Design Life Cycle Planning Configuration Mgmt. Feasibility Analysis Code COTS Tailoring COTS
USC - CSCI - 577
Team Number: Week: Program Size (SLOC) Base Added Deleted Modified Reused # of COTS Total New SLOC Effort (Hours) Project Mgmt. Requirements COTS Assessment Design Life Cycle Planning Configuration Mgmt. Feasibility Analysis Code COTS Tailoring COTS
USC - CSCI - 577
Team Number: Week: Program Size (SLOC) Base Added Deleted Modified Reused # of COTS Total New SLOC Effort (Hours) Project Mgmt. Requirements COTS Assessment Design Life Cycle Planning Configuration Mgmt. Feasibility Analysis Code COTS Tailoring COTS
USC - CSCI - 577
Team Number: Week: Program Size (SLOC) Base Added Deleted Modified Reused # of COTS Total New SLOC Effort (Hours) Project Mgmt. Requirements COTS Assessment Design Life Cycle Planning Configuration Mgmt. Feasibility Analysis Code COTS Tailoring COTS
USC - CSCI - 577
ID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15Task Name Inception First Team Interaction Members' time preferences Assigning Roles Project Detail discussion Client meeting preperation First Client Meeting Team &amp; Client Introduction Project Overview Collabo
USC - CSCI - 577
ID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27Task Name Inception First Team Interaction Members' time preferences Assigning Roles Project Detail discussion Client meeting preperation First Client Meeting Team &amp; Client I
USC - CSCI - 577
ID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32Task Name Inception First Team Interaction Members' time preferences Assigning Roles Project Detail discussion Client meeting preperation First Client Meeting
USC - CSCI - 577
ID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32Task Name Inception First Team Interaction Members' time preferences Assigning Roles Project Detail discussion Client meeting preperation First Client Meeting
USC - CSCI - 577
ID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32Task Name Inception First Team Interaction Members' time preferences Assigning Roles Project Detail discussion Client meeting preperation First Client Meeting
SUNY Stony Brook - MAT - 127
Answers to the MAT127 Homework No.12 Chapter 7 Section 4 Problem 2-4,7,10 &amp; Section 5 Problem 2,5,7,8,11,13,14,15 Section 7.4 2.(a) Let P (t) be the population of bacteria w.r.t. time t in the unit of hour, and let k be the relative growth rate in th
SUNY Stony Brook - MAT - 127
1 Show thatf (x) =n=0(1)n x2n (2n)!is a solution of f + f = 0. Solution. Writef (x) =n=0 2n(1)n x2n1 (2n)!f (x) =n=02n(2n 1)(1)n x2n2 = (2n)!n=02n(2n 1)(1)n x2(n1) (2n)!Notice that we can begin the above sum by n = 1 since
UCSC - CHEM - 112
Chemistry 112B: Organic Chemistry Winter 2008 Professor Rebecca Braslau Assigned Homework Problems The following problems are required, and must be turned in. Problems are to b e done without looking at the answers as much as possible, then corrected
SUNY Stony Brook - MAT - 126
Quiz 4 - Solutionsdx Question 1. The integral 0 2x1 is improper because 2x1 1 is not dened at 1 . 2 1 Question 2. Notice that e2x + 3 &gt; e2x , so e2x1+3 &lt; e2x . We then obtain: 0 1ex dx &lt; e2x + 3 0ex dx = e2x 0ex dxThis last integral is
SUNY Stony Brook - MAT - 126
Quiz 3 - Solutions Question 1. We want to compute x2 dx+a2 using the substitution x2 x = a tan , &lt; &lt; ; a is some positive real number. 2 2 From x = a tan we get dx = a sec2 d and x2 + a2 = a2 + a2 tan2 = a 1 + tan2 . Recalling that 1 + tan2
SUNY Stony Brook - MAT - 125
1 Problem 37 section 4.1. We have the situation shown in the gure, where v is the velocity, (xb , yb ) are the coordinates of the runner, xa is the x-coordinate of the runners friend (we do not show the y -coordinate of the runners friend since it is
SUNY Stony Brook - MAT - 211
MAT211 - Introduction to Linear Algebra SUMMER 07 Practice Final Question 1. Find 1 0 A= 0 the rank of the 23 1 B = 1 22 01 1 matrices: 11 147 1 1 C = 2 5 8 11 369Question 2. Is the matrix below invertible? In case yes, nd its inverse: 100
SUNY Stony Brook - MAT - 127
Answers for HW 1 9. 3 + 5 n2 lim = lim n n + n2 n 10. 1+ n+1 = lim n 3 n 3n 1 lim 11. 12 2n = lim ( )n = 0. n 3 3 n 3n+1 lim 12. lim 1 n n 19. Consider f (x) = x2 ex =x2 ex . 1 n 1 n 3 +5 n2 1 n +1=0+5 = 5. 0+1=1+0 1 =. 30 31 1 = = 1. 0
SUNY Stony Brook - MAT - 127
Answers for HW 11 2.Since ey dy = we get ey = 2 x 2 + C . 3 3. If y = 0, then 1 dy = y which means ln |y | = So nally y = A x2 + 1, A R. 5. From 1+ x2 x dx, +13x dx,1 ln(x2 + 1) + C. 2sin y dy = cos yx2 + 1 dx,we get (since sin ydy = d
SUNY Stony Brook - MAT - 127
Answers to the MAT127 Homework No.2 Chapter 8 Section 2 Problem 5, 7, 9, 19, 20, 25-28, 33, 36, 43 5. Divergent. Because tan n does not convergent to 0. 7. Convergent. SinceNn=11 1 1.5 n (n + 1)1.5 1 21.5 1 1 1.5 + 1.5 2 3 1 1 N 1.5 (N + 1)1.
SUNY Stony Brook - MAT - 126
Solutions for the second quizQuestion 1. We have:2 1x 3 x4 dx = x222 1x dx + x212 13x4 dx = x22 11 dx 3 x2x2 dx =1ln |x|13x3 2 3= ln 2 ln 1 (23 13 ) = ln 2 7xa+1 a+1Remember that the formula xa dx = case we
SUNY Stony Brook - MAT - 123
MAT123 - Introduction to calculus Second Practice Midterm The Second Midterm will be on Tuesday 11/11 at 8:30pm at Harriman 137. Important: check the webpage to get a copy of Second Midterm of Fall 2007! Question 1. Compute: (a) log2 (16) (b) ln e3 +
SUNY Stony Brook - MAT - 126
MAT126 Calculus B Solutions to some practice problems sec 4.9, problem 24. Find f if f (x) = 4 6x 40x3 and f (0) = 2, f (0) = 1. Computing the antiderivative: f (x) = f (x)dx = (4 6x 40x3 )dx = 4x 6 x2 x4 40 + C 2 4= 4x 3x2 10x4 + C f (0)
SUNY Stony Brook - MAT - 127
Math 127 - S2008 Practice Test for the Final Examination1. Show that the function y =Ccos(x) x2is a solution of the dierential equationx2 y + 2xy = sin(x). For what value of C does the solution satisfy the initial condition y(2) = 0? 2. Find th
SUNY Stony Brook - MAT - 126
MAT 126 Summer 08 Practice Final Question 1. Compute the derivative of the given functions: (a) f (x) = (b) g (x) =x (sin(2t) 4+ et cos t)dt6x3 esin u du x sec u+Question 2. Evaluate the indenite integrals: (a) (3x 5.73)13 dx (c) (e) a+b
SUNY Stony Brook - MAT - 126
MAT 126 Summer 08 Practice Midterm NAME: Question 1. Estimate the area under the graph of f (x) = 36 x2 from x = 0 to x = 5 using ve approximating rectangles and right endpoints. Is your estimate an underestimate or an overestimate? Question 2. Exp
SUNY Stony Brook - MAT - 127
Answers to the MAT127 Homework No.8 Chapter 8 Section 8 Problem 1-3, 9, 10, 13, 14 1. 1 21+x =n=0nxn11 ( 22 1 1)( 2 n) ( 1 n + 1) n 2 x n!= 1+n=1 = 1+n=1(1)n1 1 3 5 (2n 3) n x 2n n!So an =(1)n1 135(2n3) , 2n n!t
SUNY Stony Brook - MAT - 127
Answers for HW 9 3. Usually, one may compute the 1st, 2nd and 3rd derivatives of f at to get the 6 T3 . For this problem, one may also use sin(y + z ) = sin y cos z + cos y sin z to get the whole Taylor series of f. Just take y = x and z = .(Sinc
SUNY Stony Brook - MAT - 127
Math 127 - Spring 2008 Practice for First Examination1. Calculate the following limit if it exists. e2n + n5 e5n . n n4 (3ne2n + 1)(4e3n + 5n) lim 2. Determine whether the seriesn=11 + ln(n) (1+ln(n)2 e nis convergent or divergent. Justify yo