(C/C++) Interview in English. - Memory Allocation/Deallocation.
Q: What is the difference between
new/delete and malloc/free?
A: Malloc/free do not know about constructors and destructors. New and delete
create and destroy objects, while malloc and free allocate and deallocate
memory.
Q:What is difference between new
and malloc?
A: Both malloc and new functions are used for dynamic memory allocations and
the basic difference is: malloc requires a special "typecasting" when
it allocates memory for eg. if the
pointer used is the char pointer then after the processor allocates memory then
this allocated memory needs to be typecasted to char pointer i.e (char*).but
new does not requires any
typecasting. Also, free is the keyword used to free the memory while using
malloc and delete the keyword to free memory while using new, otherwise this
will lead the memory leak.
Q: What is the
difference between delete and delete[]?
A: Whenever you allocate memory with new[], you have to free the memory using
delete[]. When you allocate memory with 'new', then use 'delete' without the
brackets. You use new[] to
allocate an array of values (always starting at the index 0).
Q: What is difference between
malloc()/free() and new/delete?
A: malloc allocates memory for object in heap but doesn't invoke object's
constructor to initialize the object. new allocates memory and also invokes
constructor to initialize the object. malloc()
and free() do not support object semantics, does not construct and destruct
objects, new and delete can be overloaded in a class "delete" first
calls the object's termination routine (i.e. its destructor) and then releases
the space the object occupied on the heap memory. If an array of objects was
created using new, then
delete must be told that it is dealing with an array by preceding the name with
an empty []
Q: What is the difference between
"new" and "operator new" ?
A:"operator new" works like malloc.
Q: What is Memory alignment??
A:
The term alignment primarily means the tendency of an address pointer value to
be a multiple of some power of two. So a pointer with two byte alignment has a
zero in the least signi_cant bit.
And a pointer with four byte alignment has a zero in both the two least
signi_cant bits. And so on. More alignment means a longer sequence of zero bits
in the lowest bits of a pointer.
(C/C++) Interview in English. - Memory Allocation/Deallocation.的更多相关文章
- 内存管理(memory allocation内存分配)
Memory management is the act of managing computer memory. The essential requirement of memory manage ...
- Memory Allocation with COBOL
Generally, the use of a table/array (Static Memory) is most common in COBOL modules in an applicatio ...
- C++ TUTORIAL - MEMORY ALLOCATION - 2016
http://www.bogotobogo.com/cplusplus/memoryallocation.php Variables and Memory Variables represent st ...
- Linux下TomcatVM参数修改:Native memory allocation (mmap) failed to map 3221225472 bytes for committing reserved memory.
不可行的方法最初我直接修改catalina.sh, 将JAVA_OPTS变量加上了 -server -Xms1G -Xmx1G -XX:+UserG1GC最初看起来没啥问题,但是当服务器运行几天后,发 ...
- Memory Allocation in the MySQL Server
https://dev.mysql.com/doc/internals/en/memory-allocation-mysql-server.html MySQL Internals Manual / ...
- (C/C++) Interview in English - Basic concepts.
Question Key words Anwser A assignment operator abstract class It is a class that has one or more pu ...
- .NET Memory Allocation Profiling with Visual Studio 2012
.NET Memory Allocation Profiling with Visual Studio 2012 This post was written by Stephen Toub, a fr ...
- Memory Allocation Error
Memory allocation error happened when I tried to install MySQL 5.7.13 in my server, which has 2G mem ...
- [C++] 2D Array's memory allocation
2D Array's memory allocation
随机推荐
- Objective-c——UI基础开发第六天(UITableView)
一.UITableView的简单使用 显示要素: 1.显示多少给区组 2.显示多少行数据 3.每行显示什么内容 代理不会提醒你有什么方法没调用,但是UITableViewDataSource会 1)用 ...
- Oozie的安装过程
依赖CDH5,JDK和关系数据库 集群规划 主机名 IP Ooize节点 CHD1 XX.XX.XX.XX oozie server,oozie ...
- scala言语基础学习四
伴生对象 object方法构造函数只会执行一次.伴生对象和对象之间private对象可以互相访问 让object继承抽象类 apply方法 可以不new就构造对象 类似于var s = ArrayBu ...
- Java继承_接口练习题
1.创建一个名称为StaticDemo的类,并声明一个静态变量和一个普通变量.对变量分别赋予10和5的初始值.在main()方法中输出变量值. 编写代码如下: package org.hanqi.pr ...
- cron 配置计划任务的书写格式(quartz 时间配置)
一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素. 按顺序依次为 1.秒(0~59) 2.分钟(0~59) 3.小时(0~23) 4.天(月)(0~31,但是你需要考虑你月的天数) 5 ...
- poj1680 最短路判环
题意:有多个银行可以换钱,每个银行可以将特定的两种钱相互兑换,并且有自己的汇率,现在问是否可以将自己的钱通过银行兑换增加. 其实比较水,主要就是知道最短路问题里的负环可以通过bellman-fold或 ...
- javaScript call 函数的用法说明
call 方法 请参阅 应用于:Function 对象 要求 版本 5.5 调用一个对象的一个方法,以另一个对象替换当前对象. call([thisObj[,arg1[, arg2[, [,.ar ...
- Android调用系统分享功能以及createChooser的使用
工程结构 //效果图 点击测试分享 ...
- 理解MySQL——复制(Replication)
1.复制概述 1.1.复制解决的问题数据复制技术有以下一些特点:(1) 数据分布(2) 负载平衡(load balancing)(3) 备份(4) 高可用性(high avai ...
- webstorm修改文件,webpack-dev-server不自动编译刷新的解决办法
webstorm设置中,"Settings"--"Appearance & Behavior"--"System Settings" ...