当前位置:网站首页>[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
边栏推荐
- How do the TMUX color palette work?
- Cusdis - 轻量级、隐私优先的开源评论系统 | 倾城之链
- What are the SQL aggregate functions
- Experience of epidemic prevention and control, home office and online teaching | community essay solicitation
- 同花顺是正规平台吗?同花顺开户安全吗
- Of the seven levels of software testers, it is said that only 1% can achieve level 7
- 如何卸载cuda
- 常用的软件测试工具清单,请查收。
- 文件系统 -- 磁盘基础知识和FAT32文件系统详细介绍
- Software testing salary in first tier cities - are you dragging your feet
猜你喜欢

Talking about the advantages of flying book in development work | community essay solicitation

数据库系统概论必背知识

Folding screen will become an important weapon for domestic mobile phones to share the apple market

内网学习笔记(5)

Are programmers from Huawei, Alibaba and other large manufacturers really easy to find?

When they are in private, they have a sense of propriety

当他们在私域里,掌握了分寸感

3 years of testing experience. I don't even understand what I really need on my resume. I need 20K to open my mouth?

Lizuofan, co-founder of nonconvex: Taking quantification as his lifelong career

Please run IDA with elevated permissons for local debugging.
随机推荐
02-Epicor二次开发常用代码
获取图片外链的方法–网易相册[通俗易懂]
Viewing MySQL password on Linux_ MySQL forgets password "suggestions collection" under Linux
文件系统 -- 磁盘基础知识和FAT32文件系统详细介绍
Smartctl opens the device and encounters permission denied problem troubleshooting process record
中信证券手机开户是靠谱的吗?安全吗
Constant current circuit composed of 2 NPN triodes
当他们在私域里,掌握了分寸感
Qt中使用QDomDocument操作XML文件
How do the TMUX color palette work?
内网学习笔记(7)
|How to analyze bugs? Professional summary and analysis
linux上查看mysql的密码_Linux下MySQL忘记密码「建议收藏」
Resolution of cross reference in IDA
When an interface has an exception, how do you analyze the exception?
Multimodal emotion recognition_ Research on emotion recognition based on multimodal fusion
Sumati gamefi ecological overview, element design in the magical world
Are programmers from Huawei, Alibaba and other large manufacturers really easy to find?
Once beego failed to find bee after passing the go get command Exe's pit
【Proteus仿真】Arduino UNO+继电器控制照明设备

