Started experimenting with placement new
and delete
along with memory alignment and it feels like being brainy smurf in papas smurf's lab.
Lets say I have an object e.g.,
struct obj {
...
};
and I want to allocate in aligned storage an array with N
such objects. What I do is:
obj *buf = new (static_cast<obj*>(_aligned_malloc(sizeof(obj) * N, 64))) obj[N];
That is, I use placement new in combination with _aligned_malloc
.
Q
- Is this way of allocating aligned storage proper?
- Is it OK (probably not) to use
delete []
to deallocate afterwards or I need some special handling?
P.S
I know that _aligned_malloc
is not standard but rather MVSC specific.