Today's Question:  What are you most afraid of as a programmer?        GIVE A SHOUT

Technical Article => Programming =>  C++

new expression vs operator new in C++

  sonic0002      2012-08-12 11:42:39      3,077    0    0

In C++, there is a new mechanism for memory allocation and management. When we want to initialize an object, we can use new expression to get enough memory for storing an object and also initialize the object. When we want to create a new object, we can use new expression, for example:

Obj *obj=new Obj;

Basically, what the new expression does is to allocate enough memory for storing the obj object, in addition, it will initialize the object with some intial values.

Also, there is an operator new existing in C++, what it does is to allocate raw memory. It only controls allocating memory, not including the initiliation of object. It isn't much different from malloc(). We can call operator new explicitly:

char*x =static_cast<char*>(operatornew(10));

New expression cannot be overloaded, but operator new can be overloaded. You can define your own way to allocate memory in your class implementation.

For more information, you can refer :

The operator new function

The new operator



Share on Facebook  Share on Twitter  Share on Google+  Share on Weibo  Share on Reddit  Share on Digg  Share on Tumblr    Delicious



No comment for this article.


Project Ara, Another of Google’s Speculation. This time for modular phones

By hanryjames
Google is very adamant with the test of their new modular phones, nicknamed as Project Ara. The company is auspicious about the new concept where consumers can design their own phones by assembling parts from different manufacturers. The company is hopeful that there will be 20 to 30 interchangeable