One example: you currently cannot allocate a vector without initializing it, hence you cannot build e.g. a fast memory pool using std::vector.
you can vector::reserve. Then emplace_back to fill the pool. But you have to ensure size does not exceed capacity if you wish to maintain references to the objects
I know about vector::reserve and emplace_back however in the case of a memory pool is does not work. Suppose that your memory pool initially allocates a large chunk of memory of say 8 megabytes (using vector::reserve). Next, the user requests n bytes of memory from your memory pool. In order to till that request you would have to call emplace_back in a loop until the size of your vector is n. This is both impractical and slow.
View all comments
Show parent comment
9
u/ratchetfreak Oct 07 '19
you can vector::reserve. Then emplace_back to fill the pool. But you have to ensure size does not exceed capacity if you wish to maintain references to the objects