The "Go" handle, reference, pointer, and object

Source: Internet
Author: User

(1) The pointer is the address of the object in memory, and (2) the reference is the alias of the object, which is essentially a pointer with limited functionality but a higher security; (3) The handle is a pointer to a pointer, and the handle is actually a data, which is a long (full-length) data. A handle is an identifier that identifies an object or item as if it were our name. Windows is a virtual memory-based operating system. In this system environment, the Windows Memory manager often moves objects back and forth in memory to meet the memory needs of various applications. The object being moved means that its address has changed. If the address always changes, where should we go to find the object? To solve this problem, the Windows operating system frees up some internal storage addresses for each application to specifically register the address changes in memory for each application object, and the address (the location of the storage unit) itself is unchanged. When the Windows Memory Manager moves the object's location in memory, it stores the address of the new object to the handle.

Then we go back to Java to explain the problem:

There are 3 data types in Java: The base data type, the reference type, and the null type. Where reference types include class types (with arrays), interface types. To distinguish between variable identifiers of reference types and base data type variable identifiers, we specifically (deliberately) use handle to address variable identifiers of reference types. The reference to the object is the return value when the object is created! The reference is the return value of the new expression. New A (); The object is actually created here, but we do not have the handle to hold the reference (hold, take, save). Handle is a variable, and reference is a variable value.

A = new A ();

(1) The handle a--is usually a a, or a a=new a (), the former is not initialized, the latter is manually initialized. (If a is a member variable of a class, it is initialized by default.) The handle differs from the key of the basic variable, which is an indirect addressing method. A handle declaration is often referred to as an object declaration (if you feel that it is possible to cause confusion and ignore the object declaration).

(2) Create Object--new A (); This is the real object to create. Objects are typically created with new expressions.

(3) Calculate the value of the new expression: the entire process of calculating the value of the new expression, the creation of the object and the initialization of the object's own member variable on the microscopic level, and the value of the new expression on the macro, which is called the reference of the novel object;

(4) Reference: The value of new A (). A reference can be simply regarded as the address of an object occupying memory space, and it can be conveniently distinguished from other objects by reference to the object's unique identity.

(5) Initialization of the handle: Handle = reference, which assigns a reference to a handle, such as a statement a=new A (), and after the initialization of the handle, the object can be remotely controlled with a handle.

(6) For statement a a=new a (); Is the merging of object creation and object initialization with the initialization of the handle.

Transferred from: http://www.cnblogs.com/lsjwzh/archive/2010/05/08/1730480.html

The "Go" handle, reference, pointer, and object

Related Article

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.