Program memory analysis and program memory Analysis

Source: Internet
Author: User
Tags gety

Program memory analysis and program memory Analysis

It has been several years since I learned the programming language. However, the call relationship between the syntax in the programming language in the computer memory has been unclear until recently, I learned something about Java. So here is a summary.

 

First, let's look at a piece of code:

Class Point {private double x; private double y; Point (double x1, double y1) {x = x1; y = y1;} public double getX () {return x ;} public double getY () {return y;} public void setX (double I) {x = I;} public void setY (double j) {y = j ;}} class Circle {private Point o; private double radius; Circle (Point p, double r) {o = p; radius = r;} Circle (double r) {o = new Point (0.0, 0.0); radius = r;} boolean contains (Point p) {double x = p. getX ()-o. getX (); double y = p. getY ()-o. getY (); if (x * x + y * y> radius + radius) return false; else return true;} public void setO (double x, double y) {o. setX (x); o. setY (y);} public Point getO () {return o;} public double getRadius () {return radius;} public void setRadius (double r) {radius = r ;} public double area () {return 3.14 * radius;} public class TestCircle {public static void main (String arg []) {Circle c1 = new Circle (new Point (1.0, 2.0), 2.0); Circle c2 = new Circle (5.0 ); // slightly ***********************
}}
When the program executes the phrase "Circle c1 = new Circle (new Point (1.0, 2.0), 2.0);", the program resolves the statement one by one from inside to outside.

The memory usage is as follows:

Medium, the large box on the left indicates the stack in the memory, and the right indicates the heap in the memory.

When the program creates an object, it always calls a constructor of the object to assign values to the object parameters.



In the figure, the large box on the left represents the stack in the memory, and the right represents the heap in the memory.








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.