answersLogoWhite

0


Best Answer

The new operator in C++ works in a similar manner to malloc in C, allocating memory from the heap (the free store). However, unlike malloc which returns a void* pointer to uninitialised memory, the new operator returns a pointer of the given type and invokes the appropriate constructor for that type. Moreover, every class of object can overload its new operator to allow construction within memory that has been allocated in advance. That memory is typically allocated through a resource handle (known as an allocator), however we can also override the global new operator if we need to provide our own memory management.

We can still use malloc in C++, however it has no advantages over the new operator and is best avoided in the interests of consistency and, more importantly, type safety. In practice we rarely use the new operator unless we are actually designing our own resource handles or low-level memory allocators. The standard library already provides highly efficient resource handles for the vast majority of our everyday needs, so it is rarely necessary to design our own. Nevertheless, the facility exists for those (very) rare occasions where we really do require "raw" memory.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar
More answers
User Avatar

AnswerBot

1mo ago

The new operator in programming is used to allocate memory for a new object or instance of a class. It helps in dynamic memory allocation and object creation at runtime, allowing for flexible memory management and object instantiation in languages like Java and C++.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the advantages of the new operator?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Difference between new operator and operator new?

new operator allows to allocate a memory from the heap..... so a new instance of a class is created.......... but operator new is used to overload the (new) operator........ juast like overloading of other operators


What happen when a java keyword new is used in an application?

When the new operator is used, a new object is created, based on the specified class.When the new operator is used, a new object is created, based on the specified class.When the new operator is used, a new object is created, based on the specified class.When the new operator is used, a new object is created, based on the specified class.


What are the release dates for The New Operator - 1911?

The New Operator - 1911 was released on: USA: 24 July 1911


What is the use of new operator?

A new operater is used to allocating a memory space for a particular object.


How can you can create a new operator through operator overloading?

You cannot create any new operators in C++. You can only overload the existing ones (although some, such as sizeof, new and delete cannot be overloaded). The only way to create a new operator is to implement it as a standard function with a named identifier. For instance, sqrt() is the standard library function that provides the square root operator, for which no real operator exists.


What are the release dates for The Elevator Operator - 2005?

The Elevator Operator - 2005 was released on: USA: 5 March 2005 (New York City, New York)


What is operator in php?

An operator merges two different values and outputs a new expression based on the inputted values.


Which is a valid conditional formatting operator found in the New Formatting Rule dialog box?

Equal Sign (=) is a valid conditional formatting operator found in the New Formatting Rule dialog box.Equal Sign (=) is a valid conditional formatting operator found in the New Formatting Rule dialog box.


What is the fine for unlicensed operator in new york?

It $ 225.00


Explain how objects are created in Java?

with new operator


What is the significance of keyword 'new' in instance creation?

It's not just a keyword, it is also an operator in instance creation. This operator starts the sequence of constructing a new instance of object.


What is the memory management operator in c plus plus?

There is no memory management operator in C++ -- it is an unmanaged language. You use the C++ new operator to allocate memory, and use the C++ delete operator to release previously allocated memory.