473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Doesn't new operator allocate heap memory

If the built-in operator keyword new doesn't allocate memory on heap
and it calls global operator new (::operator new) or class member
operator new to do that. What are the two kinds of operator new used to
allocate heap memory?

Before there aren't global and member operator new, the built-in
operator keyword new does really allocate heap memory, right?

Nov 25 '06 #1
2 2960
lovecreatesbea...@gmail.com wrote:
If the built-in operator keyword new doesn't allocate memory on heap
and it calls global operator new (::operator new) or class member
operator new to do that. What are the two kinds of operator new used to
allocate heap memory?

Before there aren't global and member operator new, the built-in
operator keyword new does really allocate heap memory, right?
It might be called somthing else but for most intents and purposes it
behaves just like memory allocated by malloc/free. You can't use free()
to release memory allocated by operator new or visa versa tho.

Nov 25 '06 #2
lovecreatesbea...@gmail.com wrote:
If the built-in operator keyword new doesn't allocate memory on heap
and it calls global operator new (::operator new) or class member
operator new to do that. What are the two kinds of operator new used to
allocate heap memory?
This is the confusing part of C++. When you have something like:

T* ptr = new T;

the followings are performed:

1. Either the default operator new or an overloaded version is called
to obtain raw memory large enough to fit a T object.
2. The constructor of T is called.

The operator new, as in the function you can overload, only allocates
raw memory. The keyword new does that plus constructing the object.

By default, new allocates memory from the heap, or the free store. You
can overloaded either globally or specific to a class to provide
alternate memory management, usually to

- tweak performance
- inspect memory allocation
- debug the program
>
Before there aren't global and member operator new, the built-in
operator keyword new does really allocate heap memory, right?
That, I don't know.

Ben
Nov 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
0
by: Robert Potthast | last post by:
Hello, I want to make my garbage collector more safe. To make it more safe I need to know if an object has been allocated on the stack or on the heap using the operator new. My garbage collector...
3
by: toton | last post by:
Operator overloading has a sort syntax rather than member function call for stack based memory allocation. like complex<int> c1,c2,c3; c3= c1+c2; How the same can be applied to heap based...
15
by: mangesh | last post by:
This code is from c++ faq in section 11 : void someCode() { char memory; void* p = memory; Fred* f = new(p) Fred(); f->~Fred(); // Explicitly call the destructor for the placed object }
6
by: Christian Christmann | last post by:
Hi, a general question on the "new" operator. Creating object dynamically using "new" might lead to problems, when e.g. not sufficient memory is available and the object could not be created on...
3
by: Lighter | last post by:
The C++ Standard Doesn't Permit Overloading new and delete? In the 13.5 of The C++ standard (ISO/IEC 14882, 1998), I cannot find the specification on overloading the operators new and delete;...
5
by: cikkamikka | last post by:
Hi friends, Sorry for such basic question. but I wanted to know where does new operator or malloc operator allocate memory? in actualy physical Main memory or virtual memory?
11
by: Bryan Parkoff | last post by:
I want to know how much static memory is limited before execution program starts. I would write a large array. The large array has 65,536 elements. The data size is double word. The static...
1
by: =?Utf-8?B?QWxhbWVsdQ==?= | last post by:
I have overloaded a new operater for a class that returns void * and i have created an object for that class in heap as below. CMyClass *pMyClass = new CMyClass(); // Here though i haven't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.