Understand memory storage for various data types and simple classes.

Source: Internet
Author: User

The base data type. int, char short.


int A;
The A tag represents the data for an address, and the data type is int. So it accounts for 4 bytes.
A=3;
Give the label of the base data type straight. It is equal to the data of the address represented by the tag.
Since a tag represents the data of an address, its address is obtained using &A.
&a:0x22ff1c:03 00 00 00
& (&a) will be wrong because &a is not somewhere in memory.

The array type.


int a[3]
First, a[0],a[1],a[2] is as understanding as the basic data type.
The a[0] tag represents the data for an address, and the data type is int. So it accounts for 4 bytes.
So ibid & (a[0]),& (a[1])
& (A[0]): 0x22ff04

You can no longer need to know the extra knowledge here. Data and addresses are available.

Originally a does not have any meaning in itself.

However & (A[0]), the representative's first address is too large for the program. Pass the argument, return, etc.
So use A to represent & (A[0]), A+1 Representative & (A[1])
But a is an address constant. Many situations want to change a to other straight, so that the pointer, the equivalent of a this address constant into memory, with a (type *) type to represent.

is the pointer type. An inaccurate understanding is actually a 2-byte address that holds the first address of a mutable array.


Pointer type.


char * a= "ag!";
First, a[0],a[1],a[2], *a, * (a+1), * (a+2) and basic data types are understood as well.

So Ibid. & (A[0]),& (a[1]) A, a+1


The *a tag represents the data for an address, which accounts for 4 bytes of data. The first address is stored.
The definition must be (type * a). Because only the first address is not. You must know what type is stored. How many bytes are taken to form a single data.


A label and array type Label class, which represents the address of the first data.
c:0x403024

&a represents the address at which the first address is stored.

Class


Class A;
The meaning of the label of the class and the array class. Just use it without subscript.
A.name A.sex is as understanding as the basic data type.
So
&a.isbn:0x22ff18
In the case of a simple class, the address of the first data is the address of the class
&a:0x22ff18


The straight type does the row parameter.
void Change (Sales_item b)
The member variables of the class are all put into the stack as arguments. Of course, the out-of-function object is not modified.

Movb $0x62,0x18 (%ESP)
0X00401347MOVL $0x3,0x1c (%ESP)
0x0040134fmov 0x18 (%ESP),%eax//
0x00401353mov 0x1c (%ESP),%edx
0x00401357mov%eax, (%ESP)//class data member into the stack
0x0040135amov%edx,0x4 (%ESP)//class data member into the stack
0x0040135ecall 0x40136a <change (Sales_item) >

Reference type
void Change (Sales_item &b)

0x00401342movb $0x62,0x14 (%ESP)
0X00401347MOVL $0x3,0x18 (%ESP)
0x0040134flea 0x14 (%ESP),%eax//note the LEA directive. Here is the address into the stack. And the address of the first data member of a class object, which should be the address of the class.
0x00401353mov%eax, (%ESP)
0x00401356call 0x40136a <change (sales_item&) >

Understand memory storage for various data types and simple classes.

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.