Link to home
Start Free TrialLog in
Avatar of dib
dib

asked on

memory question

What is the exact difference between

char *pBuf = new char[10];

and

char *pBuf = (char*)malloc(10);

both will allocate space on the heap?!
ASKER CERTIFIED SOLUTION
Avatar of Blondie050798
Blondie050798

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yonat
yonat

One difference is that "new" can be re-defined by the programmer. Another, is that it is type safe (no need for the casting, no need to calculate the size if you want to allocate an array of amything bu char). But the most important difference is when you need to allocate OBJECTS, and not just plain chars: new will call the object's constructor, while malloc will not.