I am programming about some numerical problems. I know that vector supplies vector operations. But vector always allocate more memory (used when the size changes). My matrix or array never change size, and the vector operation is just +,-,dot,cross,distance
My question is that should I use vector, or simple double array with new & delete is enough for me?
Nope. Not always. And you can tell it to reserve specific amount. And even if it is, extra memory used is unnoticeable.
My question is that should I use vector, or simple double array with new & delete is enough for me?
If your array never changes sizes, a single static array would be fine (std::array even better). If not, a simple one-dimentional vector pretending to be two-dimensional (your class should handle that) would be perfect choice.
If you really do not want to use a vector, use array form of unique_ptr instead.
Note that the vector class in the standard library (std::vector) is just a container class meant to store elements. It does not have the vector math operations you mentioned.
> Somebody said that std::valarray is an unsuccessful class, and it's not recommended to use it.
It became an orphaned class when vector processors went out of vogue and expression templates became mainstream. But all compiler writers have not been ignoring it completely.
Its performance is truly horrible with the Microsoft implementation; while both GNU and LLVM have got it to perform on par with c-style array/vector. And Intel has a high performance valarray implementation.