当前位置:网站首页>[STL source code analysis] configurator (to be supplemented)
[STL source code analysis] configurator (to be supplemented)
2022-06-25 02:17:00 【Cloudeeeee】
List of articles
【STL Source analysis 】 Configurator ( To be added )
Number before title ( Such as “2.1 Standard interface of space configurator ” Number in 2.1 ) On behalf of the 《STL Source analysis 》 Chapter number in a book .
2.1 Standard interface of space configurator
“ Dictionaries ”:
ptrdiff_t
ptrdiff_t yes C/C++ A machine related defined in the standard library data type .ptrdiff_t Type variables are usually used to hold the results of two pointer subtraction operations .ptrdiff_t It's defined in stddef.h(cstddef) In this header file .ptrdiff_t It is usually defined as long int type .
set_new_handler(x)
Using operator new When the request for memory allocation fails , Before throwing an exception , A callback function will be called to give the programmer a chance to handle the memory allocation failure .x Represents a function pointer , Point to the programmer's own defined function when the user fails to handle memory allocation . In this code x Set to nullptr perhaps 0 It means that the programmer gives up this processing opportunity , Direct selling bad_alloc abnormal .
::operator new , ::operator delete
When we're in C++ Use in new and delete when , In fact, the implementation is global ::operator new and ::operator delete , :: Without a namespace before it, it means the default namespace of the outermost layer .
new( p ) T1(value);
It's in the pointer p The memory space pointed to creates a T1 Object of type , But the content of the object is from T2 Object of type , Is to readjust the allocated space on the basis of the existing space . This operation is to use the existing space as a buffer , This reduces the time it takes to allocate space , Because I use it directly new Operator to allocate memory , Finding enough free space in the heap is slow .
inline Inline function
Using inline functions can avoid the cost of function calls , When a function is called , In addition to the cost of function execution statements , There are many other expenses , Such as copying formal parameters 、 Restore on return, etc , When using inline functions , The program does not execute “ call ”, It is equivalent to copying the statements in the function here , Executing simple statements is faster than executing functions , Therefore, using inline functions can avoid the cost of function calls .
notes :


2.2.2 SGI Special space configurator std::alloc

2.2.3 Basic tools for construction and deconstruction :construct() and destroy()
Mainly aimed at object Structure and Deconstruction of , Before object construction , Memory Has been allocated , After the object is destructed , Memory will be released .
trivial destructor
If the user does not define a destructor , It's a self-contained system , shows , Destructors are basically useless ( But by default it will be called ) We call it trivial destructor. conversely , If a destructor is defined specifically , You need to do something before releasing space , Then this destructor is called non-trivial destructor.
2.2.4 Allocation and release of space :std::alloc
size_t
size_t The full name is size_type, Used to indicate a certain type of size 、 Number of bytes ,size_t Is a data type of record size .
The design philosophy of space configuration and release :
- towards system heap Space required in
- Consider multithreading (multi-threads) The state of ( This article does not consider multithreading )
- Consider the contingency measures in case of insufficient memory space
- Consider the problem of too much debris space
C++ Memory configuration Basic operation ::operator new() ( Global function )
C++ Memory free Basic operation ::operator delete()( Global function )
Their bottom layer uses C Linguistic malloc() Functions and free() Function to configure and release the memory space
SGI Double stage setter for ( To solve the problem of debris space ):
First level configurator (__malloc_alloc_template): Use it directly malloc() and free() Function to allocate and free space
Second level configurator (__default_alloc_template): For debris space memory pool Sorting method of
Use policy : When the configuration block exceeds 128kb when , It is considered that the space is large enough , Directly use the first level configurator ; Otherwise, use the second level configurator .



2.2.5 First level configurator __malloc_alloc_template analyse
边栏推荐
- [mobile terminal] design size of mobile phone interface
- DDD concept is complex and difficult to understand. How to design code implementation model in practice?
- Multimodal emotion recognition_ Research on emotion recognition based on multimodal fusion
- 会自动化—10K,能做自动化—20K,你搞懂自动化测试没有?
- MOS管相关知识
- 3年测试经验,连简历上真正需要什么都没搞明白,张口就要20k?
- Build and train your own dataset for pig face recognition
- 华泰证券如何开户能做到万分之一?证券开户安全可靠吗
- Application of TSDB in civil aircraft industry
- 02 common codes for Epicor secondary development
猜你喜欢
随机推荐
Application of TSDB in civil aircraft industry
产业互联网的概念里有「互联网」字眼,但却是一个和互联网并不关联的存在
软件测试人员的7个等级,据说只有1%的人能做到级别7
Specific list of regular and safe domestic stock trading account opening
When they are in private, they have a sense of propriety
|How to analyze bugs? Professional summary and analysis
入职一家新公司,如何快速熟悉代码?
做软件安全测试的作用,如何寻找软件安全测试公司出具报告?
进入阿里做测试员遥不可及?这里或许有你想要的答案
Intranet learning notes (7)
Resolution of cross reference in IDA
如何卸载cuda
基本布局-QHBoxLayout类、QVBoxLayout类、QGridLayout类
mysql命令备份
psql 列转行
TSDB在民机行业中的应用
困牛排序(寒假每日一题 40)
[I.MX6UL] U-Boot移植(六) 网络驱动修改 LAN8720A
如何选择正规安全的外汇交易平台?
What are the reasons for the abnormal playback of the online channel of the channel accessed by easycvr national standard protocol?











