array type to Array class type

How could we convert a primitive array type to Array class type as in Array lib. so it's size can be initialized dynamically by ... *arr = new ... , yet it still has Array trait which is faster than vector and has far better abilities than native array type ?
Last edited on
faster than vector and has far better abilities
What do you mean?
so it's size can be initialized dynamically
yet it still has Array trait which is faster than vector

Arrays have better performance than vectors because their size is known at compile time. If you want to initialize the size dynamically then it happens at runtime.

You can't have it both ways. Either the size is fixed at compile time or it isn't.

If you want to put a std::array on the heap then try auto *arr = new array<int,MY_SIZE>;
what problem are you trying to solve? New/delete calls done foolishly are slow, eg calling a function that has a {new ....code.... delete} design a bajillion times in a loop is slower than a design that has { .... code ...} by a significant amount, and by extension, since containers do the same thing to a degree, {container ... code... destructorcall} can also be trouble. There are tons of ways to avoid these patterns when you have this scenario without trying to recreate a 'better' stl. Vectors specifically also suffer from push-back growth if you call push back many times in a loop without any pre-allocation or the like to counter the issue, but the vector class has tools to handle this issue for you. at() is slow, because it validates; if you keep track and don't mess up indices or use safe iterators, you don't need at() so that is also self inflicted woe.

Last edited on
Topic archived. No new replies allowed.