(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
随机推荐
- js正则函数
js的正则函数主要有有replace,match,test,search,exec. 首先对文中的变量进行说明: rgExp为包含正则表达式模式和可用标志的正则表达式对象.也可以是包含正则表达式模式和 ...
- JS开发者常用的10个Sublime Text插件
Sublime Text 是每个开发者工具箱中都应该有的一个强大的应用.它是一个跨平台的.高定制化的.高级的文本编辑器,在功能强大的 集成开发环境(众所周知地消耗资源)和类似于 Vim 或 Emacs ...
- boot/setup.S
!! setup.S Copyright (C) 1991, 1992 Linus Torvalds!! setup.s is responsible for getting th ...
- vimrc配置文件_version1.0_+pathogen, taglist, wordcomplete插件说明
为了表示对Ruchee的感谢,首先这是Ruchee的个人网站:http://www.ruchee.com/index.html,他的以前很多的代码都放到Git里面了,里面有链接. 看了整整一天,刚开始 ...
- 通过ros节点发布Twist Messages控制机器人--10
原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/ 1.到目前为止,我们已经从命令行移动机器人,但大多数时间你将依靠一个ros节点发布适当的Twist消息. ...
- JavaWeb学习记录(十五)——浏览器Cookie禁用后的处理
IE禁用Cookie方式:
- hihoCoder#1080 (线段树)
题目大意:线段树的区间更改与查询,但是涉及到两种区间修改方式,一是给区间中的数全部加上一个数,二是将一个区间全部置为同一个数,然后询问整个区间和. 题目分析:处理好set操作和add操作的先后顺序就O ...
- UVA11324 强连通+dp记忆化搜索
题意:对于一个有向图,问最大团中有多少点,要求该点集内所有点对间至少有一条路径(u到v或v到u或两条都有). 首先,对于每一个强连通分量,其中的所有点必然能够互相到达,所以先进行缩点,然后对于缩点后的 ...
- vb6动态创建webbrowser
Option Explicit Private WithEvents IE As VBControlExtender Private Sub Command1_Click() Dim IE Set I ...
- linux 通用IO
open(),read(),write(),close()可以应用于管道,FIFO,socket,或者终端等所有文件类型执行IO操作. lseek()并不适用于所有类型的文件.不允许将lseek()应 ...