How To Understand New operator And operator New(II)


Transact-SQL is a programming language used in the relational database management system of Microsoft’s SQL Server. There are six main categories: arithmetic operator, assignment operator, bitwise operator, comparison operator, logical operator and string operator.

Difference between New operator and operator New

The difference between a ‘new operator’ and a operator ‘new’. When you write code like this: string * PS = new string (“Memory Management”); as above coding, you use the new operator. This operator is built-in like sizeof. You can’t change its meaning. It’s always the same function. Its functions are divided into two parts.pipe and tubing suppliers

  • The first part is to allocate enough memory to accommodate the required types of objects.
  • The second part is that it calls the constructor to initialize objects in memory. The new operator always does these two things, and you can not change its behavior in any way.

What you can change is how to allocate memory for objects. The new operator calls a function to complete the necessary memory allocation, and you can override or overload the function to change its behavior. The name of the function called by the new operator for allocating memory is operator new.

Function operator new usually declares as follows:

void * operator new(size_t size); // parameter size_t determines how much memory is allocated.

The return value type is void*, because this function returns an unprocessed pointer (raw pointer), uninitialized memory.

You do not usually call operator new directly, but once you do, you can call it just like any other function:

void *rawMemory = operator new(sizeof(string));

Leave your comment