How can I know the size of std::array, std::vector and raw array if they have same number of members and types. With size I mean the memory they occupy as a whole or in other words, I don't want any bad_alloc.
If it is a POD type that is stored in the array/vector you can just use sizeof on raw arrays and std::array. With std::vector<T> v; it's a bit more complicated. First we have the size of the vector itself sizeof(v). The size occupied by the elements v.capacity() * sizeof(T) so in total sizeof(v) + v.capacity() * sizeof(T). Dynamic allocations might have additional overhead but that is ignored here.