Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ pointers vs std::vector: any implication for long size variables?

I have a C background and I am recoding some old code in C++... In the process, I am starting to use C++ Vectors, which are so easy to use!

Would vectors deal well with very long streams of data? For example, in audio apps, loading a stereo 3 minutes song would need almost 16M floats

float *stereoSong = NULL;
stereoSong = new floats[15787800];

Not having to deal with memory management with vectors is very nice, but I was wondering if that huge amount of data would be handled well by C++ vectors

Thanks!

like image 981
WewillSee Avatar asked Aug 27 '26 05:08

WewillSee


1 Answers

This is a false comparison.

For a start, vectors use pointers. They have to. Vectors are containers that use dynamic allocation to provide you with a buffer of data items. You could try to implement the same thing "with pointers", but you'd end up with something someway between a vector, and a worse version of vector.

So, vectors can handle as much data as you'd be able to handle with new double[] — that is, a lot.

like image 187
Asteroids With Wings Avatar answered Aug 29 '26 20:08

Asteroids With Wings



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!