Stenographer for one week

Source: Internet
Author: User

Disclaimer: Stenographer. It is actually a stenographer. Sort out the knowledge learned in the last week with your own understanding. Viewer self-Attention. Welcome to criticism.

    • At the operating system level.
      Recently, the project team assigned me a business requirement. Simply put, before loading large files, I can first check the current memory usage and make a rough assessment based on the limited information of the files to be loading, check whether the file will change the memory to crash. To cope with this task, I learned a little bit about the underlying memory management of the OS.
      • Memory paging is a memory management method used to unify virtual memory and physical memory.
      • (In Linux) when you writeProgramWhen the free () function is called to release the specified memory, the memory is not immediately returned to the operating system, but is still held by the current program. However, this section of memory is "protected". When the program needs to allocate memory next time, it will first use these "protected" memory, and will only apply for it from the memory pool if necessary. Of course, this setting can be changed by modifying the underlying memory ing (MAP.
      • The memory block contains the actual memory content (that is, data), and information indicating the block itself (such as the size). Otherwise, when you release a block, the operating system cannot know how much space to store. This information is a header. This header also occupies memory space. What does this mean? It means that when your program allocates a large number of small objects, memory is wasted by default OS Memory Management. Because the large amount of header information also occupies a considerable amount. To solve this problem, we need a dedicated "Object pool" memory management technology. A typical solution is boost: pool.

 

  • In the C ++ object model layer.
    I recently read the book "Deep Exploration of C ++ object models", and I feel that I can understand it a little bit now. Excited and explicit understanding.

    • C ++ directly supports three types of programming paradigms: 1) procedual model, 2) Abstract Data Type Model (abstract data type model, ADT ), 3) object-oriented model (OOM ). The ADT model emphasizes object encapsulation. When you use a specific object type (for example, when you care about its data or call its method ), you actually use this model. Some people say that this model emphasizes the concept of "Object-based. The OOM model emphasizes polymorphism ). When you use the interfaces designed by the base class to manipulate (manage) the behavior of various subclasses, you actually use this model. Some people say that this model emphasizes the concept of "Object Oriented ".
    • C ++ supports polymorphism in three ways. 1) implicitly convert a derived class pointer to a base class pointer. 2) through the virtual function mechanism, the basic class behavior is mapped to a specific subclass behavior. 3) use the dynamic_cast and typeid operators to determine and convert the subclass objects in the intent.
    • The virtual function of C ++ is actually managed by a virtual table (vtbl), which is a virtual pointer bound to an object (vptr) indexed. Vtbl is an array that stores object polymorphism information. The first element (vtbl [0]) is generally the type information of the object (for example, the information here is actually used when using dynamic_cast for judgment ), the second element is followed by a number of virtual functions (such as virtual destructor) that have been rewritten by each subtype ). Vtbl is the main overhead of extra space and time when polymorphism is used. In space, the storage object occupies more memory. In time, it is the time it takes to find the correct virtual function address or the real type of information.
    • Reference and pointer are actually the same thing at the compiler level. So you can also use the reference to use polymorphism. Only these two methods can use polymorphism.
    • If a user does not provide a default constructor when designing a type, will the compiler provide one by default? The answer is-not all. The compiler provides users only when it deems it "necessary. What is "necessary "? There are four opportunities: 1) "member Class Object with default constructor. 2) "base class with default constructor. 3) class with a virtual function. 4) "class with a virtual base class. The default constructor provided at these times is to meet the compiler's needs, that is, to initialize the necessary data objects mentioned above. In your own classes, only the Member objects that "provide default constructor" will be initialized, and other data will not be automatically (implicitly) initialized. On the other hand, what if the user provides a default constructor but does not explicitly initialize the data in the four timing listed above? The answer is -- the compiler will modify the user'sCodeAdd some code to the constructor so that the data can be initialized as expected.
    • A question that suddenly occurred to me during my reading process: If you want to index a specific member of an object through an object pointer, what is the underlying layer of the compiler? After all, all you get is a base address of the object. How does the compiler know the size of the object, and what Members are inside? Is this information stored inside the object? After some data exploration, the answer is that the object memory does not store any information about this aspect. When the compiler converts code into an assembly language, the address of the object member is automatically mapped to the address of the member, which is "hardcoded" to the underlying layer. Therefore, this problem actually no longer exists after the code is compiled.

 

  • at the design mode level.

    • I used the observer (observer) mode in my spare time practice project. This mode effectively solves the problem of "Inter-object communication. Note that an object may be either a subject or an observer object. Objects often have the need to receive messages and then spread messages as needed.
    • I also used the briage mode to solve the problem of "heavily dependent on a third-party engine \ component \ library" during development. The Design of third-party libraries is often self-contained, and the inheritance system is clear and complete. However, if you plan to design a top-down, clear and complete architecture, and use third-party libraries to complete the real work. The bridge mode is a good idea. In fact, whether you "inherit" the components of a third-party library or "include" the components of a third-party library is a choice. However, the "included" solution is more flexible, and the future architecture will become wider and wider. The "Bridge Mode" is to add a pointer to a third-party library component to the base class component in your own architecture to achieve "bridge ". In practice, some "common" data needs to be abstracted into interface classes in your own architecture tree. In addition, the bridge mode is more like the "adapter mode" in some forms. The common difference lies in "contains components", but the adaptor mode does not emphasize the "bridge ", it only emphasizes "inheriting its own interfaces and including third-party library components" to achieve "transfer.
    • In addition, The iterator mode and component mode are read. As there is no need for application, there is no practical experience. Here is one or two pieces of reading experience: the iterator mode abstracts the Traversal method for external use, and the internal can change as the saying goes, this is the so-called "change" part that requires attention. In fact, we often encounter the combination mode when learning about an architecture, such as orge's scene organization mode, such as cocos2d-x's scene-layer organization mode. After all, they are all "Trees". The node of the tree can make another sub-tree, or make a leaf (leaf ). The leaves will be the end of the tree, and no other things will be derived from them. It is the atomic data of this tree.

  •  Diary today.
    • Today, I met a young friend (who has been on a business trip in Shanghai for several months ). After a meal, tell me off and chat. It is not easy to know what to do, and they all have their own ideas. This is what we call "the barrier is like the mountain". As a programmer, I do regard technology (and industry-related) exploration as a kind of enjoyment with a little pride, but it is also easy to "look blank", think that what you know is "important". What do you do with other worlds. But how is it possible. I have a narrow vision, such as sitting in the sky, and like a half bottle of vinegar, it is really ridiculous. Yes or no.
    • This guy said that today is his birthday. Why should I say that. He said that his birthday had to be meaningful, and he did not care whether he had eaten the cake. Agree. So I wish him a happy birthday.
    • It will also be LP's birthday in a few days. Happy birthday to her in advance. We hope that our journey in 2013 will be better and better.

 

 

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.