dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: C++
Expertise: Beginner
Jul 18, 2000

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


New & Malloc

Question:
I understand that most of the time, new and malloc may use the same allocation routines, but does that necessarily mean new calls malloc? I am asking because I want to see all the memory being allocated in my program, but I use both new and malloc. If it's possible, I would like to just overwrite malloc instead of both malloc and new.

Answer:
The C++ standard doesn't specify whether new calls malloc() to allocate raw memory. It's implementation-dependent. Some compilers may use malloc() as the underlying allocation routine whereas others use a different allocation routine. Therefore, it's best not to assume that new calls malloc() because even if it's the case, future releases of your compiler might use a different allocation routine. Instead, define your own version of malloc() and have your custom operator new call it.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date