Class Note for CMPSCI 377 at UMass(42)
Class Note for CMPSCI 377 at UMass(42)
Popular in Course
Popular in Department
This 3 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Massachusetts taught by a professor in Fall. Since its upload, it has received 14 views.
Reviews for Class Note for CMPSCI 377 at UMass(42)
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/06/15
CMPSCI 377 Operating Systems Spring 2007 Lecture 3 September 13 Lecturer Emery Berger Scribes Alea Schultz Alden Wheeler 31 C and C basics 311 Why C over Java C is low level and allows direct access to the com uter which 6ives the ro rammer a greater degree of I a a a a control over the system In Java the programmer is insulated form the computer hardware and operating y tem by the Java runtime environment 312 Systems programming C is a better choice for systems programming I Fast and space ef cient I Low Level Very close to the machine architecture I Direct access to memory 313 Code Visibility What you see is what you get I In C what you code is what the computer does I In Java each action you take is backed up by many calls done by the runtime environment whether or not you absolutely need them all Example Garbage Collection I In C there are no quotreadquot or quotwritequot barriers that is garbage collection is not done by the C language I In Java every time an object reference is changed the garbage collector must be alerted to check for references to the old object to see if that ObjCL space can be reused This tacks on a performance hit so that one does not have to manage their own variable pointers and references 314 Hardware Devices All the Java code that actually quottalksquot to the hardware of your computer is written in C 31 3 2 Lecture 3 September 13 315 Why C over C C extends C in a couple of ways I Upward compatibility C code can be compiled with a C compiler Classes like the ones used in Java for better structuring of data and algorithms I Encapsulation allows public pr39ivate members of classes Templates which are analogous to Java generics Inlining instead of macros for increased efficiency by inserting function code directly where it is called Macros also allowed you to do evil substitutions like switching while loops to if statements 32 Similarities and Dissimilarities between Java and C 321 Conditionals For the most part conditionals are the same between Java and C However in C any non zero value will evaluate to true 322 Command line arguments In Java the main function is passed an array of strings that have the command line arguments In C C the values passed in are a pointer to an array of characters that hold the command line arguments as well as an integer with the size of the array 323 Pointers and References In Java you are not allowed to directly look at memory address s whereas in C you can A pointer is a variable that holds the memory address of another variable and is declared using A reference is declared using a t and allows you to get the address of a variable so that a pointer may point to it this is called dereferencing a variable 324 Parameter Passing and Returning In C all variables are copied when they are passed which means that any changes made in the function the variable is passed to will not echo back to the original y passed variable In order to return your results you should pass in the value to be worked on by reference and return the value by reference which will save it from being destroyed after the function dies 325 Stack Heap and Explicit Memory Management Variables either live on the stack which is intended for temporary variables in a function or on the heap which is used for persistant objects throughout a program In CC the heap is explit ly managed by Lecture 3 September 13 the programmer The fact that the stack is volatile in the way it stores data can introduce problems when using pointers in a function as those pointers will point to garbage once the function has ended To allocate new data on the heap use the newquot ke or39d but you must remember to delete the variable or39 else you will be facing a memory leak due to the wasted variable in the heap However deleting them too soon when they are still in use can crash the program by forcing a pointer to point to a non era stant chunk of data in the memory Deleting a variable twice can also crash the program by causing calls to new to continually write to the same piece of memory 326 Arrays Arrays in C C have no bounds checking and no w r39 of checking length unlike in Java It is up to the programmer to keep track of the length of the array so that neighboring locaiton in memory are not overwritten by calls to the array
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'