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. Docker简介

    Docker简介 1.容器虚拟化,比传统的虚拟化轻量 2.2013年出现,发展非常迅猛 3.Redhat在6.5版本开始支持docker 4.使用go语言开发,基于apache2.0协议 5.开源原件 ...

  2. 國王遊戲(2012年NOIP全国联赛提高组)

    题目描述 Description 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n位大臣排成 ...

  3. 课堂所讲整理:HTML--8Window.document对象

    1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:    var a =docunmen ...

  4. jquery轻松操作CSS样式

    $(this).click(function(){  if($(this).hasClass(“zxx_fri_on”)){    $(this).removeClass(“zxx_fri_on”); ...

  5. java的nio之:java的nio系列教程之SocketChannel

    Java NIO中的SocketChannel是一个连接到TCP网络套接字的通道.可以通过以下2种方式创建SocketChannel: 打开一个SocketChannel并连接到互联网上的某台服务器. ...

  6. 《Python自然语言处理》中文版-纠错【更新中。。。】

    最近在看<Python自然语言处理>中文版这本书,可能由于是从py2.x到py3.x,加上nltk的更新的原因,或者作者的一些笔误,在书中很多代码都运行不能通过,下面我就整理一下一点有问题 ...

  7. ABBYY PDF Transformer+ Pro支持全世界189种语言

    ABBYY PDF Transformer+ Pro版支持189种语言,包括我们人类的自然语言.人造语言以及正式语言.受支持的语言可能会因产品的版本不同而各异.本文具体列举了所有ABBYY PDF T ...

  8. ABBYY是怎么自定义主窗口的

    启动 ABBYY FineReader OCR文字设别软件时,将打开其主窗口.同时将显示任务窗口,可以启动内置或自定义自动化任务. 主窗口显示目前打开的 ABBYY FineReader 文档. ● ...

  9. nginx-gridfs使用

    安装nginx及nginx-gridfs 依赖库.工具   # yum -y install pcre-devel openssl-devel zlib-devel # yum -y install ...

  10. docker nodejs 基本应用

    1. 安装docker 环境 2. nodejs  应用布局 package.json { "name": "docker-centos-hello", &qu ...