I noticed that the memory for vector is allocated dynamically. So for a local vector, where does the memory is allocated?
f(){
vector<int> vi;
}
The vector is allocated on the stack (28 bytes on my system). The vector contents are allocated on the heap.
You can change how memory is allocated for STL containers with the combination of Allocator template type and the allocator object passed to the constructor.
I asked a question about how to make a vector use stack storage and got this answer. You might find it interesting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With