当前位置:网站首页>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 ).
边栏推荐
- PHY驱动调试之 --- PHY控制器驱动(二)
- Inclusion exclusion principle acwing 890 Divisible number
- A brief introduction to heading/pitch/roll and omega/phi/kappa
- Game theory acwing 891 Nim games
- MPLS experiment
- The route of wechat applet jumps again without triggering onload
- 使用paping工具进行tcp端口连通性检测
- Adg5412fbruz-rl7 applies dual power analog switch and multiplexer IC
- Xavier CPU & GPU high load power consumption test
- SOC_SD_DATA_FSM
猜你喜欢

Find the combination number acwing 889 01 sequence meeting conditions

confidential! Netease employee data analysis internal training course, white whoring! (attach a data package worth 399 yuan)

Orin 安装CUDA环境

VLAN experiment

NVM Downloading npm version 6.7.0... Error

ROS2——topic话题(八)

Some classic recursion problems

Vant Weapp SwipeCell设置多个按钮
![[Gaode map POI stepping pit] amap Placesearch cannot be used](/img/4c/55586ffcc2267c477a4532ab51a0c1.png)
[Gaode map POI stepping pit] amap Placesearch cannot be used

cgroup_ memcg
随机推荐
Xavier CPU & GPU 高负载功耗测试
Empire help
Find the combination number acwing 889 01 sequence meeting conditions
. Net core stepping on the pit practice
Adg5412fbruz-rl7 applies dual power analog switch and multiplexer IC
Technical conference arrangement
Error: "mountvolume.setup failed for volume PVC fault handling
Design specification for mobile folding screen
数据库Mysql全部
H5 模块悬浮拖动效果
.net core踩坑实践
Find the combination number acwing 888 Find the combination number IV
解读最早的草图-图像翻译工作SketchyGAN
Game theory acwing 894 Split Nim game
GDB code debugging
Rehabilitation type force deduction brush question notes D2
Stack acwing 3302 Expression evaluation
在本地搭建一个微服务集群环境,学习自动化部署
6-3 find the table length of the linked table
Redis-02. Redis command