My STL Learning Path

Source: Internet
Author: User

Speaking of STL (Standard Template Library), I believe that the understanding of C + + is not unfamiliar bar ^_^. LZ is from the junior start to learn C + + (PS: not trained), and slowly contact with the use of STL, in the school using STL more cases is to write data structure code, using STL implementation of data structure code (my data structure source), so that we focus on thinking about the algorithm, not rigidly adhere to the underlying code implementation.

Here LZ does not talk about the specific knowledge of STL, only discuss the study and use of STL problems! Combining the LZ learning process, LZ feels that C + + learning (of course, which includes the STL) roughly routes the following:

    1. Learn basic C + + syntax
    2. Mastering concepts such as class, inheritance, polymorphism, etc.
    3. Understanding face objects and generic programming ideas
    4. Understanding and using STL (Standard Template Library)
    5. Read STL's main code implementation to deepen the understanding of STL
    6. Explore the C + + object model (this will understand the memory layout of the class object, how the polymorphism is implemented ...) )

Learn C + + (including STL), of course, read books, especially classic books, refer to the above learning route, the corresponding recommended books are as follows:

1/2/3: "C + + Primer" is a comprehensive and authoritative description of C + + basic concepts, technology, and modern C + + programming style, is the best guide for C + + beginners, Bible-grade books.

4/5: "STL Source Analysis" in-depth analyses of STL sources (SGI version), to help you deepen the understanding of STL, the future use of STL is assured of boldness.

6: The Deep Exploration C + + object model focuses on the underlying mechanisms of C + + object-oriented programming, including structured semantics, generation of temporary objects, encapsulation, inheritance, and virtual-virtual functions and virtual inheritance to help you understand the underlying implementation of the program in order to write more efficient code.

Of course, in the course of learning, you can read effective C + + to help you write more robust C + + code. Learn C + + and STL to read these books, other C + + books can no longer look.

1. What is STL?

The STL (Standard Template Library) was developed by Alexander Stepanov, Meng Lee and David R Musser when they worked in HP Labs. Fundamentally, STL is a collection of "containers" that have list,vector,set,map and so on, and STL is also a collection of algorithms and other components. The collection of "containers" and algorithms here refers to many of the world's most intelligent people for many years. The purpose of the STL is to standardize the components so that they do not have to be re-developed and can use ready-made components, and STL is now part of C + +.

The STL provides six components, and the components can be combined with each other:

    • Container (Containers): A variety of data structures, such as: vector, List, deque, set, map. Used to store data. From an implementation point of view, the STL container is a class template.
    • Algorithm (algorithms): A variety of common algorithms, such as: Sort, search, copy, erase. From the implementation point of view, the STL algorithm is a function template.
    • Iterator (iterators): A binder between a container and an algorithm, which is called a "generic pointer". There are five types, as well as other derivative changes. From an implementation perspective, an iterator is a class template that Overloads operator*, Operator->, operator++, operator--and other pointer-related operations. All STL containers have their own unique iterators, and only the container itself knows how to traverse its own elements. The native pointer (native pointer) is also an iterator.
    • Functor (functors): behaves like a function, which can be used as a strategy for an algorithm. From an implementation point of view, the functor is a class or class template that overloads the operator (). The general function pointer can also be considered as a narrow-sense imitation function.
    • Adapter (adapters): something that modifies a container, an imitation function, an iterator interface. For example: The queue and stack provided by STL, although seemingly containers, can only be considered as a container adapter because the bottom of them is fully deque, and all operations are supplied by the underlying deque. Change functors interface, called function adapter, change container interface, called container adapter, change iterator interface, called iterator adapter.
    • Configurator (allocators): Responsible for space configuration and management. From the point of view of implementation, Configurator is a class template which realizes dynamic space configuration, space management and space release.
STL The interaction between the six components

2, the actual project in the company should not use STL?

There are many discussions on the web about STL, such as why some companies do not allow the use of STL? Is STL really supposed to work? ... Here combined with the LZ's actual work experience, to talk about the use of STL, LZ is currently in a certain China to do security platform development, the project used STL, but the project is mostly used in the STL container, iterator parts, such as algorithms and other parts rarely used. LZ felt that in the actual project to make no use of STL, mainly to see the actual needs of the project, according to the specific use of the scene to choose. The security platform is mainly responsible for communication with the device, storage device sent up pictures and video, and web-side interaction, and so on, because the platform access equipment is limited, so there will not be a lot of concurrency, the use of STL fully meet the requirements.

The use of STL avoids the encapsulation of the underlying data and focuses more on the implementation of the business logic, but the use of STL may result in code bloat, memory usage efficiency, type implicit conversion issues, which can be a performance bottleneck in projects where the volume of data is large or the project concurrency requirements are higher. STL containers are not thread-safe and need to be self-locking when used in multi-threading.

3. Continue to learn C + +

Learn C + +, in addition to classic books there is another important resource, that is open source code. Read the open source code, do not enter to understand the code specification, but also in-depth understanding of how the system is implemented, deepen the understanding of technology. Read the source code at the same time, you can try to build wheels, about C + +, there are a few more classic source:

    • Leveldb:google, follow the Google C + + coding specifications. The author is Jeff Dean's great God.
    • Libevent: is an open-source event-driven library based on the infrastructure provided by OS such as Epoll,kqueue.
    • TEAMtalk: Mushroom Street Open source Instant Messenger software, with PC, Android, iOS version, where Server side is C + + implementation.
    • ...

Resources

1. Why are some companies not allowed to use C + + STL?

2. The first section of STL source analysis

3, C + + implementation of data structure source code

My STL Learning Path

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.