当前位置:网站首页>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.
边栏推荐
- [IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production
- Learn C language from scratch day 025 (maze)
- Modeling essays series 124 a simple coding method
- new和malloc的区别
- 迁移云计算工作负载的四个基本策略
- What are the skills of spot gold analysis?
- Luogu p1775 stone merger (weakened version)
- Learn about servlets
- New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
- Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
猜你喜欢
卷积神经网络(包含代码与相应图解)
What is AQS and its principle
Raspberry pie 4B learning notes - IO communication (1-wire)
基于SSM实现微博系统
Ks006 student achievement management system based on SSM
如何远程、在线调试app?
SAP ui5 beginner tutorial 20 - explanation of expression binding usage of SAP ui5
[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility
[IVX junior engineer training course 10 papers to get certificates] 09 chat room production
Since I understand the idea of dynamic planning, I have opened the door to a new world
随机推荐
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
Altium designer measure distance (ctrl+m)
Convolutional neural network (including code and corresponding diagram)
笔者更加愿意将产业互联网看成是一个比消费互联网要丰富得多的概念
matlab 实现语音信号重采样和归一化,并播放比对效果
[Maya] the error of importing Maya into Metahuman
[Chongqing Guangdong education] Tianshui Normal University universe exploration reference
Learn C language from scratch day 025 (maze)
Modeling essays series 124 a simple coding method
k线图形态这样记(口诀篇)
Three core problems of concurrent programming
Docker安装Oracle_11g
只是以消费互联网的方式和方法来落地和实践产业互联网,并不能够带来长久的发展
Game thinking 15: thinking about the whole region and sub region Services
【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
The technology boss is ready, and the topic of position C is up to you
Have you stepped on the nine common pits in the e-commerce system?
5g/4g pole gateway_ Smart pole gateway
并发编程的三大核心问题
2022年6月国产数据库大事记