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 matched delete[] / new() delete
  • they communicate different things. operator new(n) request memory unspecified purposes, whereas new 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() returns void* 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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -