Deep Exploration C + + object Model (2)

Source: Internet
Author: User
Tags continue object model

Slein: I just read your "deep explore C + + object Model (1)" And it feels good. But I have a suggestion: You say "Behold the first chapter is so difficult to digest, has repeatedly read 3 times, or some half-cooked" is very natural. The first chapter is an overview, if you can read it all, there is no need to see the back. The first chapter of the content behind are introduced in detail, the beginning as long as there is a general impression on it. Many of the contents of the book are repetitive. I suggest that you do not understand or understand, just look back, and then look at the beginning of several times, so the effect is much better.

I think what Lein said should be a very good way of reading, similar to the "Deep Exploration of C + + object Model" Such technical books, need to understand, and learning English is different, not by rote, if there is no understanding of the situation, then you might as well put down the book, play a red police (I am proud to say, I am a master). Or skip the past is also a good way. OK, let's continue to study the C + + object model.

A Simple object model

An example of a book (an annotation is an index that represents Solt)


Class Point
{
Public
Point (float xval); 1
Virtual ~point (); 2

float x () const; 3
static int Pointcount (); 4
Protected
Virtual ostream& print (ostream &os) const; 5
float _x; 6
static int _point_count; 7
}


Each object is a series of slots, each of which points to a slots.

Table-Driven object model

When you construct an object, you have a pointer array that holds pointers to the position of class data members in memory, and pointers to member functions. In order to have a standard representation of all object entities generated by a class, so the object model takes a table, puts all the data members in the data member table, puts all the member function addresses in the member function table, and the class object itself has pointers to the two tables.

For the sake of understanding, Thor to give an inappropriate example to illustrate that the attention is not a very appropriate example we regard the office building as a class, the Office of the people as a class of data members, and each of the office rental companies as a member of the class function. Let's look at an entity, we call it the Thor building. The property Management Department of Raytheon Building needs to register every person in and out of the office for a pass, and to register the room number of each company and make a sign on the wall of the hall. In fact, this is the object construction process of the class. You can find any company that rents a house in the Raytheon building through a list of companies on the wall of the lobby, or you can find anyone who has access to the Thor building through a property roster.

This is an example of how you can test your imagination. (If you have a better example, don't forget to communicate with Thor).

The object model of C + +

The C + + object model derives from the Simple object model and optimizes the memory space and access time. It introduces the scheme of virtual function table (virtual table). Each class produces a bunch of pointers to virtual functions, placed in a table. Objects of each class are added with a pointer (vptr), pointing to the associated virtual function table (virtual table). This pointer is automatically completed by the constructor, destructor, and copy assignment operators of each class.

We also use the Thor building above for example, property management in order to improve efficiency, long-term stability of the company and personnel no longer registered, refers to the unstable or uncertain company registration, to facilitate management.

Test everyone's imagination again.

It is concluded that the C + + object model and the two-table object model improve the efficiency of space and storage time, but lose the elasticity.

Imagine that there is no list of people and companies throughout the Raytheon Building, and if they change, then the property Management department needs to do a lot of work. To redefine the long-term stability of companies and people are those. The corresponding application requires recompilation. (This is even more outrageous, but in order to keep it coherent, you have to think about it in an understandable way, without limiting its literal meaning)

This note is written in a little bit of time, and even one hours a day is not guaranteed (no way to be busy recently), so there may be incoherence, and if you read it very uncomfortable that Thor's mind shorted out, that's normal. However, the Thunder god or upload before the efforts to the idea of finishing. Hope to be able to string these words together.

Finally, read the "Deep C + + object Model" a book feel nothing can be the focus of things, feel that every word should not let go, all the focus. After repeated reading, Thor seems to have some kind of enlightened, continue to work hard, I and everyone is.

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.