当前位置:网站首页>The difference between new and malloc
The difference between new and malloc
2022-07-05 06:50:00 【An embedded enthusiast】
new and malloc The difference between
1、new Allocate memory from free storage ,malloc Allocate memory from the heap . Free storage is C++ be based on new An abstract concept of an operator , Usually through new Operator for memory request , This memory is the free storage area . And heap is an operating system term , It is a special memory maintained by the operating system , For dynamic allocation of program memory . So can a free storage area be a heap ( The problem is equivalent to new Whether memory can be allocated dynamically on the heap ), It depends. operator new Implementation details . Free storage can be more than just a heap , It can also be static storage , It's all up to you operator new Where to allocate memory for objects .
2、new、delete Returns a pointer to a data type ;malloc、free The return is void The pointer .
3、 Use new Operators do not need to specify the size of memory block when applying for memory allocation , The compiler computes itself based on the type information ; Use malloc You need to explicitly indicate the size of memory required .
4、new You can call the constructor of an object , Corresponding delete Call the corresponding destructor ;malloc Just allocate memory ,free Just reclaim memory , Construction and destructors are not executed . stay new When an object , The first call malloc Allocate memory space for objects , And then call the constructor of the object. .delete Will call the object's destructor , And then call free Reclaiming memory .
5、new、delete It's the operator , Can overload ;malloc、free Is the function , Can be rewritten ( Cover ).
边栏推荐
- mysql设置触发器问题
- Integer to 8-bit binary explanation (including positive and negative numbers) scope of application -127~+127
- H5 module suspension drag effect
- Page type
- 数据库Mysql全部
- how to understand the “model independent.“
- Technology blog learning website
- Marvell 88e1515 PHY loopback mode test
- UIO driven framework
- Stack acwing 3302 Expression evaluation
猜你喜欢
ROS2——功能包(六)
Orin installs CUDA environment
Chinese remainder theorem acwing 204 Strange way of expressing integers
ROS2——ROS2对比ROS1(二)
Marvell 88E1515 PHY loopback模式测试
Mutual transformation between two-dimensional array and sparse array (sparse matrix)
Rehabilitation type force deduction brush question notes D2
Orin two brushing methods
how to understand the “model independent.“
MPLS experiment
随机推荐
. Net core stepping on the pit practice
Application of recyclerview
'mongoexport 'is not an internal or external command, nor is it a runnable program or batch file.
Error: "mountvolume.setup failed for volume PVC fault handling
The “mode“ argument must be integer. Received an instance of Object
Game theory acwing 893 Set Nim game
Orin two brushing methods
Sre core system understanding
[MySQL 8.0 does not support capitalization of table names - corresponding scheme]
Game theory acwing 891 Nim games
PHY驱动调试之 --- PHY控制器驱动(二)
About vscode, "code unreachable" will be displayed when calling sendline series functions with pwntools“
.net core踩坑实践
namespace
H5内嵌App适配暗黑模式
inux摄像头(mipi接口)简要说明
Huawei bracelet, how to add medicine reminder?
2. Addition and management of Oracle data files
Time is fast, please do more meaningful things
Chinese remainder theorem acwing 204 Strange way of expressing integers