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
Post a Comment