J
Jef Driesen
Is it allowed by the C++ standard to mix the use of 'new/delete' and
'operator new/delete'?
(a) alloc (version 1) + free (version 2)
(b) alloc (version 2) + free (version 1)
// VERSION 1 ALLOC (using operator new + placement new)
type* data = (type*)operator new(n * sizeof(type));
for (type* p = data; p != data + n; ++p)
new ((void *)p) value_type();
// VERSION 1 FREE (using calling destructor + operator delete)
for (type* p = data; p != data + n; ++p)
p->~type();
operator delete(data);
// VERSION 2 ALLOC (using new)
type* data = new type[n];
// VERSION 2 FREE (using delete)
delete [] data;
'operator new/delete'?
(a) alloc (version 1) + free (version 2)
(b) alloc (version 2) + free (version 1)
// VERSION 1 ALLOC (using operator new + placement new)
type* data = (type*)operator new(n * sizeof(type));
for (type* p = data; p != data + n; ++p)
new ((void *)p) value_type();
// VERSION 1 FREE (using calling destructor + operator delete)
for (type* p = data; p != data + n; ++p)
p->~type();
operator delete(data);
// VERSION 2 ALLOC (using new)
type* data = new type[n];
// VERSION 2 FREE (using delete)
delete [] data;