C++: is malloc equivalent to new? -


possible duplicate:
what difference between new/delete , malloc/free?

hi guys noob in c++, want know whether

memblock = (char *)malloc( currentbytelength);  

is equivalent

memblock = new char[currentbytelength] 

in c++.

memblock = (char *)malloc( currentbytelength);   memblock = new char[currentbytelength]; 

no difference now. if replace char int, yes, there difference, because in case, malloc allocate memory of size currentbytelength, while new allocate memory of size size(int) * currentbytelength. very careful.

also, if type mention in new expression, user-defined type, default constructor called currentbytelength number of times, construct objects!

for built-in types, there no constructor!


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -