I am building a game that consists of rooms with portals leading to other rooms.The camera,the shadow maps and reflections need to build their own collection of rooms before rendering. My concern is that I dont want to recreate the vectors each time for each view. Is there a way to preallocate a chunk of memory and make vectors use THIS chunk of memory for their content?
Asked
Active
Viewed 58 times
0
-
4[`std::vector::reserve`](https://en.cppreference.com/w/cpp/container/vector/reserve)? – MikeCAT Jul 03 '20 at 13:47
-
reserve will just randomly request memory from the heap by requesting the OS, will it not? – Raildex Jul 03 '20 at 13:49
-
I suggest using your own container instead of std::vector. This is pretty normal for games. – user253751 Jul 03 '20 at 13:53
-
My [answer](https://stackoverflow.com/a/62646894/3972710) for another question give link to polymorphic allocator and pmr namespace allowing to use your own buffers – NGI Jul 03 '20 at 14:05
-
4Yes, all containers that have allocator template argument (like std::vector) can be made to use specific chunk of memory by programming such allocator that does it. – Öö Tiib Jul 03 '20 at 14:16
-
reserve() will allocate the necessary memory you need resize() will allocate the necessary memory you need and add all the objects to the list. You will need to pass the vector to other locations by reference and store it at a higher level to keep from recreating it. – szMuzzyA Jul 03 '20 at 15:46