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. android:clipToPadding 和 android:clipChildren 解决ListView设置padding后 padding不跟随改动

    clipToPadding就是说控件的绘制区域是否在padding里面的,true的情况下如果你设置了padding那么绘制的区域就往里 缩, clipChildren是指子控件是否超过padding ...

  2. SpringMVC4零配置--Web上下文配置【MvcConfig】

    与SpringSecurity的配置类似,spring同样为我们提供了一个实现类WebMvcConfigurationSupport和一个注解@EnableWebMvc以帮助我们减少bean的声明. ...

  3. c 深度剖析 1

    1.register register 变量必须是能被CPU寄存器所接受的类型(32 位机器 寄存器为32位),必须是单个的值,长度小于或等于整形的长度 不能用&来获取register 变量的 ...

  4. mysql创建用户和创建数据库赋值用户操作权限

    mysql 进入mysqldb SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user; ...

  5. IOS请求H5页面、要求自定义agent判断是电脑、安卓还是iPhone登录

    //自定制的userAgent- (void)createMyAgent{        NSString *userAgent = [[[UIWebView alloc]init]stringByE ...

  6. kuangbin_ShortPath N (POJ 1847)

    模板题辣很简单的 只有两种val 0 和1 #include <iostream> #include <string> #include <cstdio> #inc ...

  7. Scrum 项目2.0

    阅读教材第8章,8.1~8.3节 P157~168,了解获取用户需求的办法,每个组可以选择一二加以应用. 8.4节P168-171 查阅NABCDA模型的具体说明. 2.SCRUM 流程的步骤 1 完 ...

  8. 使用四种框架分别实现百万websocket常连接的服务器

    著名的 C10K 问题提出的时候, 正是 2001 年.这篇文章可以说是高性能服务器开发的一个标志性文档,它讨论的就是单机为1万个连接提供服务这个问题,当时因为硬件和软件的**,单机1万还是一个非常值 ...

  9. MapReduce: 一个巨大的倒退

    前言 databasecolumn 的数据库大牛们(其中包括PostgreSQL的最初伯克利领导:Michael Stonebraker)最近写了一篇评论当前如日中天的MapReduce 技术的文章, ...

  10. Linux启动新进程的三种方法

    程序中,我们有时需要启动一个新的进程,来完成其他的工作.下面介绍了三种实现方法,以及这三种方法之间的区别. 1.system函数-调用shell进程,开启新进程system函数,是通过启动shell进 ...