当前位置:网站首页>The difference between new and malloc
The difference between new and malloc
2022-07-02 01:42:00 【wrdoct】
new and malloc difference (8 individual )
(1)new and delete yes C++ Of keyword / Operator ,malloc And free yes c++/c The standard of language function .
(2)malloc need Explicitly specify the allocated memory size ,new Unwanted .
(3)new Operator from Free storage area Upper object Dynamic allocation Memory space , and malloc Function from Pile up Dynamic allocation of memory on .
【 notes 】 Usually through new Operator for memory request , This memory is the free storage area .
(4)new When operator memory allocation succeeds , Return object type , No type conversion required , so new Is in accordance with Type safety Sex operator ;malloc return void*, Need to pass through Cast take void* The pointer is converted to the type we need .
(5)new When the operator memory allocation fails , Throw out bad_alloc abnormal ;malloc Return when memory allocation fails NULL.
(6)new The operator There are constructors and destructors , While opening up space , The constructor of the custom object will be called to complete initialization ;malloc It will only open up space .
(7)malloc After allocating space , Can pass realloc Expand memory ;new Operator cannot expand memory again .
(8)new relative malloc Low efficiency , because new The bottom layer encapsulates malloc.
边栏推荐
- 电子协会 C语言 1级 33 、奇偶数判断
- 开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
- MPLS experiment operation
- Using tabbar in wechat applet
- No converter found for return value of type: class
- 电商系统中常见的9大坑,你踩过没?
- Basic number theory -- Gauss elimination
- New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
- 机器学习基本概念
- Ks006 student achievement management system based on SSM
猜你喜欢

【LeetCode 43】236. The nearest common ancestor of binary tree

2022年6月国产数据库大事记

【疾病检测】基于BP神经网络实现肺癌检测系统含GUI界面

Single chip microcomputer -- hlk-w801 transplant NES simulator (III)

遷移雲計算工作負載的四個基本策略
![[IVX junior engineer training course 10 papers to get certificates] 0708 news page production](/img/ad/a1cb672d2913b6befd6d8779c993ec.jpg)
[IVX junior engineer training course 10 papers to get certificates] 0708 news page production

Three core problems of concurrent programming

6-3 vulnerability exploitation SSH environment construction

Matlab uses audioread and sound to read and play WAV files

matlab 使用 audioread 、 sound 读取和播放 wav 文件
随机推荐
Three core problems of concurrent programming
Study note 2 -- definition and value of high-precision map
2022年6月国产数据库大事记
Discussion on the idea of platform construction
[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me
[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card
Learning note 24 - multi sensor post fusion technology
Design and implementation of radio energy transmission system
[disease detection] realize lung cancer detection system based on BP neural network, including GUI interface
There are spaces in the for loop variable in the shell -- IFS variable
Develop those things: how to use go singleton mode to ensure the security of high concurrency of streaming media?
Edge computing accelerates live video scenes: clearer, smoother, and more real-time
[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility
Learning notes 25 - multi sensor front fusion technology
Laravel artisan common commands
The smart Park "ZhongGuanCun No.1" subverts your understanding of the park
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
The technology boss is ready, and the topic of position C is up to you
NeRV: Neural Reflectance and Visibility Fields for Relighting and View Synthesis
Exclusive delivery of secret script move disassembly (the first time)