c++ - operator new(n) versus new unsigned char[n] for placement new -
i'm allocating memory later used constructing objects placement new. should using operator new(n), or should using new unsigned char[n]? why?
factors:
new[]must matcheddelete[]/new()delete- they communicate different things.
operator new(n)request memory unspecified purposes, whereasnew unsigned char[n]loosely implies intent store characters there.
the array form may slightly worse performance / efficiency wise - exact details depending on implementation:
5.3.4/12 new t[5] results in call of operator new x non-neagtive unspecified value representing array allocation overhead: result of new-expression offset amount value returned
operator new[]....
btw - neither initialised:
operator new()returnsvoid*uninitialised memory: see 3.7.4.1/2 "there no constraints on contents of allocated storage on return allocation function", whereas 5.3.4/15 says "a new-expression creates object of type t initializes object follows: if new-initializer ommitted, object default-initialized (8.5)"; 8.5/6 says class types default constructors provide initialisation.
Comments
Post a Comment