CSC 253 Lecture 2. Some differences between Java and C  Compiled C code is machine specific, whereas Java compiles for a virt. machine.  Virtual machines.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Computer Architecture CSCE 350
Kernighan/Ritchie: Kelley/Pohl:
CPSC 388 – Compiler Design and Construction
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
CS61C L05 C Structures, Memory Management (1) Garcia, Spring 2005 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
Run-Time Storage Organization
Run time vs. Compile time
Memory Allocation and Garbage Collection. Why Dynamic Memory? We cannot know memory requirements in advance when the program is written. We cannot know.
C and Data Structures Baojian Hua
CS 61C L03 C Arrays (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #3: C Pointers & Arrays
CS100A, Fall 1997, Lectures 221 CS100A, Fall 1997 Lecture 22, Tuesday 18 November Introduction To C Goal: Acquire a reading knowledge of basic C. Concepts:
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Memory Layout C and Data Structures Baojian Hua
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
JAVA v.s. C++ Programming Language Comparison By LI LU SAMMY CHU By LI LU SAMMY CHU.
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
CENG 311 Machine Representation/Numbers
COP4020 Programming Languages
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap.
Introduction to Programming Languages. Problem Solving in Programming.
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Lists and More About Strings CS303E: Elements of Computers and Programming.
CS352-Week 2. Topics Heap allocation References Pointers.
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
This set of notes is adapted from that provided by “Computer Science – A Structured Programming Approach Using C++”, B.A. Forouzan & R.F. Gilberg, Thomson.
Introduction and Features of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 7 OS System Structure.
Storage Management. The stack and the heap Dynamic storage allocation refers to allocating space for variables at run time Most modern languages support.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 15: More-Advanced Concepts.
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CPSC 252 Dynamic Memory Allocation Page 1 Dynamic memory allocation Our first IntVector class has some serious limitations the capacity is fixed at MAX_SIZE.
1 Dynamic Memory Allocation –The need –malloc/free –Memory Leaks –Dangling Pointers and Garbage Collection Today’s Material.
Dynamic Memory Allocation. Domain A subset of the total domain name space. A domain represents a level of the hierarchy in the Domain Name Space, and.
Computer Programming 2 Why do we study Java….. Java is Simple It has none of the following: operator overloading, header files, pre- processor, pointer.
CS 100Lecture 211 Announcements P5 due on Thursday FINAL EXAM Tuesday August 10, 8AM, Olin 155 Review sessions on Thursday and Friday Final grades posted.
Runtime System CS 153: Compilers. Runtime System Runtime system: all the stuff that the language implicitly assumes and that is not described in the program.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Computer Graphics 3 Lecture 1: Introduction to C/C++ Programming Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora.
Pointers. Variable Declarations Declarations served dual purpose –Specification of range of values and operations –Specification of Storage requirement.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Announcements There is a Quiz today. There were problems with grading assignment 2, but they should be worked out today The web page for correcting the.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 7 – Pointers.
Memory Management in Java Mr. Gerb Computer Science 4.
CS 61C: Great Ideas in Computer Architecture C Pointers Instructors: Vladimir Stojanovic & Nicholas Weaver 1.
Data Types Chapter 6: Data Types Lectures # 13. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
C11, Implications of Inheritance
Computer Organization and Design Pointers, Arrays and Strings in C
Chapter 10 Programming Fundamentals with JavaScript
Interpreted languages Jakub Yaghob
Key Ideas from day 1 slides
ENEE150 Discussion 07 Section 0101 Adam Wang.
Dynamic Memory Allocation
Storage Management.
Dynamic Memory Allocation
CSC 253 Lecture 8.
CMSC 341 Prof. Michael Neary
Storage.
CSC 253 Lecture 8.
Memory Allocation CS 217.
CS100A Lecture November 1998 Prelim 3 Statistics Maximum 94
Programming Languages
CSC 253 Lecture 2.
Run-time environments
IS 135 Business Programming
CSE 303 Concepts and Tools for Software Development
Presentation transcript:

CSC 253 Lecture 2

Some differences between Java and C  Compiled C code is machine specific, whereas Java compiles for a virt. machine.  Virtual machines are much slower than natively executed code.  Compiled code can interact with specifics of that machine (e.g., devices).  Java does “automatic” memory management.  In C, you must free memory explicitly.  You could forget to do it … this causes a memory leak.  However, you can get by with less memory.  And, you don’t have to worry about garbage collection causing you to miss real-time deadlines.  Compiled C code is machine specific, whereas Java compiles for a virt. machine.  Virtual machines are much slower than natively executed code.  Compiled code can interact with specifics of that machine (e.g., devices).  Java does “automatic” memory management.  In C, you must free memory explicitly.  You could forget to do it … this causes a memory leak.  However, you can get by with less memory.  And, you don’t have to worry about garbage collection causing you to miss real-time deadlines.

C vs. Java  Why are OSs written in C?  The very bottom layer of sw. has to be native machine code.  Two steps in the Java compile-run sequence are “skipped” with C.  What two steps?  Interpretation—JVM xlates byte code to machine code.  What’s the advantage of skipping them?  Faster  What’s “bad” about skipping them?  Machine dependence.  No place for run-time bounds-checking.  Why are OSs written in C?  The very bottom layer of sw. has to be native machine code.  Two steps in the Java compile-run sequence are “skipped” with C.  What two steps?  Interpretation—JVM xlates byte code to machine code.  What’s the advantage of skipping them?  Faster  What’s “bad” about skipping them?  Machine dependence.  No place for run-time bounds-checking.

Pointers  Advantages?  You can perform arithmetic on pointers … this may save a few instructions.  You can get a pointer to anything in C.  Disadvantages?  “Dangling pointers”—pointers that don’t point to allocated memory anymore.  Forgetting to dereference a pointer.  Advantages?  You can perform arithmetic on pointers … this may save a few instructions.  You can get a pointer to anything in C.  Disadvantages?  “Dangling pointers”—pointers that don’t point to allocated memory anymore.  Forgetting to dereference a pointer.

Summary: Advantages of C  Efficiency  Close to the machine  Uses much less memory  You have better control of your program (talking directly to machine).  Efficiency  Close to the machine  Uses much less memory  You have better control of your program (talking directly to machine).

Summary: Advantages of Java  Portability  Safety  Less error prone  Portability  Safety  Less error prone

Variables used by > 1 function  Should they be …  Global?  …  How can such a value be passed into a function?  How can such a value be returned from the function?  Should they be …  Global?  …  How can such a value be passed into a function?  How can such a value be returned from the function?

Why not use lots of globals?  You can prevent accesses to variables from places they’re not supposed to be accessed from.  Name-space pollution.  Local variables are deallocated upon procedure returns, whereas global variables aren’t. (Uses more memory.)  You can prevent accesses to variables from places they’re not supposed to be accessed from.  Name-space pollution.  Local variables are deallocated upon procedure returns, whereas global variables aren’t. (Uses more memory.)

How can you avoid globals?  Pass pointers to structures.  You can return it from a function.  You can pass in & return pointers, and in the function, modify what’s pointed to.  Pass pointers to structures.  You can return it from a function.  You can pass in & return pointers, and in the function, modify what’s pointed to.

Why should you not do arithmetic on characters?

Let’s write a program to …  determine the value of INT_MAX ;  that is, show an integer i that prints as positive, whereas i +1 prints as negative.  determine the value of INT_MAX ;  that is, show an integer i that prints as positive, whereas i +1 prints as negative.

Let’s write a program to  look at the bits in INT_MAX and see how it’s represented in our computer.