- a pointer to the last element constructed within the managed storage |
My mistake, this would typically point one past the last element.
You're referring to something allocated on the heap with new |
Typically yes. Although
std::vector uses an
allocator to obtain memory.
> - a pointer to the end of allocated storage;
This is the pointer to one-past-the-last element? |
Recall that std::vector has a
capacity and a
size. This pointer (call it
end) is set up so that
end - start yields the capacity, not the size.
We can diagram a vector with a capacity of 8 and a size of 6 roughly like this.
[x] is an element;
[ ] is a memory cell which could contain an element:
[x] [x] [x] [x] [x] [x] [ ] [ ]
^start ^finish ^end |
In the diagram
start points to the beginning of the allocated memory,
finish points one-past-the-last element, and
end points one-past-the-end of the allocated memory.
Therefore the vector's size may be computed as
finish - start; its capacity as
end - start.
I'm not sure what the vector class in PPP looks like. However because PPP is a beginner's book it may be simplified somewhat compared to a production implementation in a standard library.