当前位置:网站首页>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 ).
边栏推荐
- Xavier CPU & GPU high load power consumption test
- [tf] Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initial
- H5 embedded app adapts to dark mode
- TypeScript入门
- [QT] QT multithreading development qthread
- NVM Downloading npm version 6.7.0... Error
- 基于FPGA的一维卷积神经网络CNN的实现(八)激活层实现
- testing framework
- How to correctly ask questions in CSDN Q & A
- Pycahrm reports an error: indentation error: unindent does not match any outer indentation
猜你喜欢

Vscode configures the typera editor for MD

1. Create Oracle database manually

Game theory acwing 892 Steps Nim game

Vant Weapp SwipeCell設置多個按鈕

Marvell 88e1515 PHY loopback mode test

【高德地图POI踩坑】AMap.PlaceSearch无法使用

将webApp或者H5页面打包成App

Record of problems in ollvm compilation
![LSA Type Explanation - lsa-1 [type 1 LSA - router LSA] detailed explanation](/img/1f/30407bce35c324cc90f139b6f09fd1.jpg)
LSA Type Explanation - lsa-1 [type 1 LSA - router LSA] detailed explanation

Find the combination number acwing 887 Find combination number III
随机推荐
【高德地图POI踩坑】AMap.PlaceSearch无法使用
Integer to 8-bit binary explanation (including positive and negative numbers) scope of application -127~+127
GDB code debugging
NVM Downloading npm version 6.7.0... Error
[Chongqing Guangdong education] National Open University 2018 autumn 0702-22t contemporary Chinese political system reference questions
new和malloc的区别
[tf] Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initial
PHY驱动调试之 --- MDIO/MDC接口22号和45号条款(一)
Architecture
Rehabilitation type force deduction brush question notes D3
Vant weapp swippecell set multiple buttons
1. Create Oracle database manually
6-4 search by serial number of linked list
6-3 find the table length of the linked table
PR automatically moves forward after deleting clips
kata container
LSA Type Explanation - lsa-5 (type 5 LSA - autonomous system external LSA) and lsa-4 (type 4 LSA - ASBR summary LSA) explanation
The “mode“ argument must be integer. Received an instance of Object
微信小程序路由再次跳轉不觸發onload
Skywalking全部