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?!
char *pBuf = new char[10];
and
char *pBuf = (char*)malloc(10);
both will allocate space on the heap?!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.