Nope, Vectors don't store their elements in contiguous memory. Each element of a Vector is a reference to an object somewhere else in memory. Depending on the language being used, the Vector's reference list may or may not be stored in contiguous memory. However, this doesn't change the function of the Vector data type. Additionally, the footprint for a reference ("pointer" for c++ people) is very small, so this quirk is considered a trait of the language itself rather than the Vector.
Compare declaring a Vector which will hold 20 elements versus declaring an array of the same size. Assuming an integer is 4 bytes and a reference/pointer/memory address is 2 bytes.
Note: Fictional scenario
int[] array = new int[20]; sets aside 4*20 blocks of contiguous memory.
Vector vector = new Vector(20); sets aside 2*20 blocks in contiguous memory (depending on the implementation/language). To fill up the vector an additional 80 bytes are required somewhere else in memory. The original 40 bytes point to the various places each int is placed.
|