My STL learning path and STL learning path

Source: Internet
Author: User

My STL learning path and STL learning path

Speaking of STL (Standard Template Library), I believe it will not be unfamiliar with C ++. ^_^. LZ has been learning C ++ since his junior year (ps: not a class background) and has been gradually involved in using STL. When STL is used in schools, data structure code is usually written, the use of STL to implement the Data Structure Code (my data structure Source Code) enables us to focus on algorithm ideas, regardless of the underlying code implementation.

Here, LZ does not talk about the specific knowledge of STL. It only discusses the learning and usage of STL! In combination with the LZ learning process, LZ feels that the general path of C ++ Learning (of course, the STL included) is as follows:

To learn C ++ (including STL), I certainly need to read books, especially classic books. Refer to the above learning path and the corresponding recommended books are as follows:

1/2/3: C ++ Primer gives a comprehensive and authoritative explanation of the basic concepts, technologies, and modern C ++ programming style of C ++, it is the best guide for C ++ beginners, Bible-level books.

4/5: STL source code analysis deeply analyzes STL source code (SGI version) to help you deepen your understanding of STL. You will be relieved to use STL later.

6: Deep Exploration C ++ object model focuses on the underlying mechanism of C ++ object-oriented programming, including structured semantics, generation, encapsulation, and inheritance of temporary objects, as well as virtual-virtual functions and virtual inheritance, it helps you understand the underlying implementation of the program to write more efficient code.

Of course, you can also read Objective C ++ to help you write more robust C ++ code. I have studied C ++ and STL to read these books. Other C ++ books do not have to be read again.

1. What is STL?

STL (Standard Template Library) was developed by Alexander Stepanov, Meng Lee, and David R Musser when they were working at the HP lab. Basically, STL is a collection of "containers", which include list, vector, set, and map. STL is also a collection of algorithms and other components. The collection of containers and algorithms here refers to the masterpiece of many smart people in the world for many years. The purpose of STL is to standardize components so that you do not need to re-develop them. You can use ready-made components. STL is now part of C ++.

STL provides six components that can be combined with each other:

  • Containers: various data structures, such as vector, list, deque, set, and map. Used to store data. From the implementation point of view, STL container is a class template.
  • Algorithms (algorithms): common algorithms, such as sort, search, copy, and erase. From the implementation point of view, STL algorithm is a function template.
  • Iterators: the glue between containers and algorithms. It is a so-called generic pointer ". There are five types and other derivative changes. From the implementation perspective, the iterator is a class template that reloads pointer-related operations such as operator *, operator->, operator ++, and operator. All STL containers have their own exclusive iterators. Only the containers themselves know how to traverse their own elements. Native pointer is also an iterator.
  • Functors: A behavior similar to a function, which can be used as a policy of an algorithm ). From the implementation point of view, the imitation function is a class or class template with operator () reloaded. A general function pointer can also be regarded as a narrow imitation function.
  • Adapters: an interface that modifies containers, functions, and iterations. For example, the queue and stack provided by STL, although seemingly a container, can only be regarded as a container adapter, because they use deque at the bottom, and all operations are supplied by the deque at the bottom. The functors interface change is called the function adapter; the container interface change is called the container adapter; The iterator adapter changes the iterator interface.
  • Allocators: responsible for space configuration and management. From the perspective of implementation, the Configurator is a class template that implements dynamic space configuration, space management, and space release.
STL Interaction between the six components

 

2. Should STL be used in actual projects of the company?

There are still many discussions on STL on the Internet. For example, why some companies do not allow STL? Shouldn't STL be used ?... Here we will talk about the use of STL based on the actual work experience of LZ. LZ is currently developing a security platform in China, and STL is used in the project, however, most of the items used in the project are containers and iterators in STL, and other parts such as algorithms are rarely used. LZ considers that STL is not used in actual projects. It mainly depends on the actual needs of projects and can be selected based on specific use cases. The security platform is mainly responsible for communicating with devices, sending pictures and videos from storage devices, and interacting with web terminals. Due to limited platform access devices, there will be no high concurrency, the use of STL fully meets the requirements.

STL is used to avoid encapsulation and processing of underlying data and focus more on business logic implementation. However, STL may cause code expansion, memory usage efficiency, and implicit type conversion, these problems may cause performance bottlenecks if the project data volume is large or the project concurrency requirements are relatively high. Note that STL containers are not thread-safe. You need to implement the lock operation on your own when using multithreading.

3. Continue to learn C ++

To learn C ++, in addition to the classic books, there is another important resource, that is, open source code. Read the open source code. If you do not enter the source code specification, you can also learn more about how the system is implemented and how to understand the technology. While reading the source code, you can try to build a wheel. For C ++, there are several typical source codes:

  • Leveldb: produced by Google, compliant with Google C ++ coding specifications. The author is Jeff Dean.
  • Libevent is an open-source event-driven Library Based on the infrastructure provided by epoll, kqueue, and other operating systems.
  • TeamTalk: mogujie.com's open-source instant messaging software, including PC, Android, and Ios versions. The Server side is implemented in C ++.
  • ...

 

References

1. Why do some companies not allow C ++ STL?

2. Chapter 1 of STL source code analysis

3. Data Structure Source Code implemented by C ++

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.