I am presently using an array to store a list of elements such that the exact length is not known in advance, only an upper bound. The elements are progressively added, and when done, it would be nice to tell the OS that the remaining space is not needed. In C, this could be done using realloc(). In C++, Stroustrup says that it's usually easier and just as efficient to use a standard container. I could use a vector and use resize when done to reduce the size to the exact amount used.
The question is, in this situation (either with realloc(), or with a C++ vector using resize), when the array or vector is downsized, does the OS typically try to copy the data elsewhere, or just leave it where it is? I guess it's a matter of avoiding memory fragmentation vs. the time involved in moving the data. If the data remains in place, it's a no-brainer to release the extra space.