Now that I think about it, someType has to be a POD-type. It can't be a struct/class with
a constructor or destructor, a struct/class with any virtual functions, or a struct/class that
is a descendant of a derived type. In short, in reality it can only be a POD type.
If you can assume then that someType has the same alignment requirements as int, then
you could figure out how many bytes the array of someTypes needs, and then allocate
an array of ints:
|
ptr = (someStruct*)new int[ 1 + numItems / 4 + ( numItems % 4 ? 1 : 0 ) ];
|
wow, that's ugly.
1 + -> because you need space for numItems.
numItems % 4 ? 1 : 0 -> because if it requires 13 bytes, 13 / 4 = 3 * 4 = 12 bytes
allocated, too few, so you need to allocate 1 additional int to make it big enough.