当前位置:网站首页>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 ).
边栏推荐
- Use ffmpeg to rotate, flip up and down, and flip horizontally
- . Net core stepping on the pit practice
- 基于FPGA的一维卷积神经网络CNN的实现(八)激活层实现
- Paper reading report
- Xavier CPU & GPU 高负载功耗测试
- Redis-02. Redis command
- Find the combination number acwing 888 Find the combination number IV
- Stack acwing 3302 Expression evaluation
- Qt项目中的日志库log4qt使用
- Pycahrm reports an error: indentation error: unindent does not match any outer indentation
猜你喜欢

ROS2——node节点(七)

Vscode configures the typera editor for MD

7. Oracle table structure

Orin 两种刷机方式

Configuration method and configuration file of SolidWorks GB profile library

Vant weapp swippecell set multiple buttons

Find the combination number acwing 887 Find combination number III

Spinningup drawing curve

Log4qt usage of logbase in QT project

Skywalking全部
随机推荐
GDB code debugging
Time is fast, please do more meaningful things
How to answer when you encounter a jet on CSDN?
Build a microservice cluster environment locally and learn to deploy automatically
ethtool 原理介绍和解决网卡丢包排查思路(附ethtool源码下载)
H5 模块悬浮拖动效果
CGroup CPU group source code analysis
Inclusion exclusion principle acwing 890 Divisible number
Getting started with typescript
睿智的目标检测59——Pytorch Focal loss详解与在YoloV4当中的实现
微信小程序路由再次跳轉不觸發onload
[Chongqing Guangdong education] National Open University 2018 autumn 0702-22t contemporary Chinese political system reference questions
[Chongqing Guangdong education] 1185t administrative leadership reference test of National Open University in autumn 2018
Edge calculation data sorting
C语言数组专题训练
Instruction execution time
Redis-01. First meet redis
7. Oracle table structure
Xavier CPU & GPU 高负载功耗测试
ROS2——Service服务(九)