当前位置:网站首页>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.
边栏推荐
- Six lessons to be learned for the successful implementation of edge coding
- 学习笔记25--多传感器前融合技术
- 如何远程、在线调试app?
- 【图像增强】基于Frangi滤波器实现血管图像增强附matlab代码
- 只是以消费互联网的方式和方法来落地和实践产业互联网,并不能够带来长久的发展
- 学习笔记2--高精度地图定义及价值
- 机器学习基本概念
- Implementation principle of city selector component
- 遷移雲計算工作負載的四個基本策略
- Based on configured schedule, the given trigger will never fire
猜你喜欢
Implementation of Weibo system based on SSM
matlab 实现语音信号重采样和归一化,并播放比对效果
How can I batch produce the same title for the video?
[IVX junior engineer training course 10 papers to get certificates] 09 chat room production
PR second training
Exclusive delivery of secret script move disassembly (the first time)
【疾病检测】基于BP神经网络实现肺癌检测系统含GUI界面
matlab 使用 resample 完成重采样
Three core problems of concurrent programming
Feature extraction and detection 16 brisk feature detection and matching
随机推荐
LeetCode、3无重复最长子序列
电子协会 C语言 1级 33 、奇偶数判断
10 minutes to get started quickly composition API (setup syntax sugar writing method)
Failed to transform file 'xxx' to match attributes
[IVX junior engineer training course 10 papers to get certificates] 0708 news page production
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
Android: the kotlin language uses grendao3, a cross platform app development framework
现货黄金分析的技巧有什么呢?
开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
[IVX junior engineer training course 10 papers] 06 database and services
Using tabbar in wechat applet
站在新的角度来看待产业互联网,并且去寻求产业互联网的正确方式和方法
电子协会 C语言 1级 32、计算2的幂
电商系统中常见的9大坑,你踩过没?
The role of artificial intelligence in network security
Design and implementation of radio energy transmission system
三分钟学会基础k线图知识
【LeetCode 43】236. The nearest common ancestor of binary tree
Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
[image enhancement] vascular image enhancement based on frangi filter with matlab code