Memory Analysis in the program

Source: Internet
Author: User

learning the programming language also has a few years, but for the programming language syntax in the computer memory of some of the call relationship has been unclear, until recently, in learning Java when you get to know something. So this concludes.

First look at a section 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 ();d ouble y = p.gety ()-o.gety (); if (x*x+y*y> radius + radius) re Turn 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 * 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 to the Circle C1=new Circle (New Point (1.0,2.0), 2.0);in this sentence, the program is parsed from inside out.

The actual memory usage is as follows:

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

when the program New an object, a constructor of the object is always called first to implement the parameter assignment to the object.



In the diagram, the large box on the left represents the stack in memory, and the right side represents the heap in memory, as is the following illustration.








Memory Analysis in the program

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.