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.的更多相关文章

  1. 内存管理(memory allocation内存分配)

    Memory management is the act of managing computer memory. The essential requirement of memory manage ...

  2. Memory Allocation with COBOL

    Generally, the use of a table/array (Static Memory) is most common in COBOL modules in an applicatio ...

  3. C++ TUTORIAL - MEMORY ALLOCATION - 2016

    http://www.bogotobogo.com/cplusplus/memoryallocation.php Variables and Memory Variables represent st ...

  4. Linux下TomcatVM参数修改:Native memory allocation (mmap) failed to map 3221225472 bytes for committing reserved memory.

    不可行的方法最初我直接修改catalina.sh, 将JAVA_OPTS变量加上了 -server -Xms1G -Xmx1G -XX:+UserG1GC最初看起来没啥问题,但是当服务器运行几天后,发 ...

  5. Memory Allocation in the MySQL Server

    https://dev.mysql.com/doc/internals/en/memory-allocation-mysql-server.html MySQL Internals Manual  / ...

  6. (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 ...

  7. .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 ...

  8. Memory Allocation Error

    Memory allocation error happened when I tried to install MySQL 5.7.13 in my server, which has 2G mem ...

  9. [C++] 2D Array's memory allocation

    2D Array's memory allocation

随机推荐

  1. LNMP环境搭建(discuz论坛)

    一.操作系统级环境及软件版本 操作系统:CentOS release 6.5 (Final)minimal 内核版本:2.6.32-431.el6.x86_64 MySQL版本:MySQL-5.6.2 ...

  2. 全国信息学奥林匹克联赛(NOIP2014)复赛 模拟题Day2 长乐一中

    题目名称 改造二叉树 数字对 交换 英文名称 binary pair swap 输入文件名 binary.in pair.in swap.in 输出文件名 binary.out pair.out sw ...

  3. Codeforces Round #148 (Div. 2)

    A. Two Bags of Potatoes 枚举倍数. B. Easy Tape Programming (待补) C. Not Wool Sequences 考虑前缀异或和. \[answer ...

  4. 【NOI2015】软件包管理器

    NOI难得的水题,话说还是T2诶……又学到了线段树的一种新的魔性使用 看sxysxy大神的代码才写出来的,sxysxy_orz 原题: Linux用户和OSX用户一定对软件包管理器不会陌生.通过软件包 ...

  5. 转贴:sudo apt-get install 可以安装的一些软件

    Ubuntu 下的一些软件安装sudo apt-get install virtualbox#华主席推荐 2007年年度最佳软件,最佳编辑选择奖得主.....sudo apt-get install ...

  6. Linux常用配置文件解析

    网络相关配置文件 1./etc/sysconfig/network-scripts/ifcfg-ethx 网络参数IP/子网掩码/广播地址等的配置(重启有效) 2./etc/resolv.conf   ...

  7. 黑马程序员——JAVA基础之内部类,匿名内部类

    ------- android培训.java培训.期待与您交流! ---------- 内部类 将一个类定义在另一个类的里面,对里面那个类就称为内部类(内置类,嵌套类). 内部类访问特点: •  内部 ...

  8. MFC开发上位机到底用Dialog结构还是文档结构?

    最近要跟着导师一起开发一款大型上位机.MFC新人在考虑用对话框结构还是文档结构. 虽然说书上说大型结构的软件都需要文档结构,但是目前来看,对话框可以实现功能,并且对话框的程序更小一些,节省资源加载速度 ...

  9. EJB 的理解

    引用源:http://blog.csdn.NET/cymm_liu/article/details/7760989 1.EJB 概念的剖析 我们先看一下,EJB 的官方解释: 商务软件的核心部分是它的 ...

  10. PHP安装libevent扩展

    1. 下载扩展 官方地址http://pecl.php.net/package/libevent 请根据自己的PHP脚本选择相应版本 如 wget http://pecl.php.net/get/li ...