Why would you do such experiment in the first place?
If it is research you would need to know why C++ use new instead of malloc
evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
Hi thanks for the links. I understand the difference and the main one is that the constructor does not get called with malloc. I guess my question is whats the difference between this:
vector< string > * u = (vector< string >*) malloc( sizeof(vector< string >)) ;
*u = vector< string >(10,"test");
Note I have called the constructor after malloc, which correct me if i'm wrong calls the constructor of vector and puts in 10 string elements all intialised to "test".
and This:
vector< string > *u = new vector< string >(10,"test");
What does new do to the memory block other than call the constructor?
Thanks
You are opening the whole can of worms. You have to find how each compiler implements the new operation and reinvent the wheel. I guess internally they use malloc/free
Here is related question: http://stackoverflow.com/questions/1031301/can-i-implement-the-factory-method-pattern-in-c-without-using-new/1031375#1031375
evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
If the problem is solved, mark it so!
evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392