
Daniel Frey wrote:
Gennaro Prota wrote:
Does the swap trick necessarily free the memory?
AFAIK, yes. See <http://www.gotw.ca/gotw/054.htm>.
The STL implementation I have been using seems to allocate a buffer on first insertion into any container of a given type, and frees it only when it feels like it (often on program shut-down). I don't know if it's a strictly conforming implementation in that respect, although I can't see anything in the standard prohibiting this behaviour. James Hopkin

jhopkin@reflectionsinteractive.com wrote:
The STL implementation I have been using seems to allocate a buffer on first insertion into any container of a given type, and frees it only when it feels like it (often on program shut-down).
Sounds like a pool allocator. Question: Does .clear() for your STL return the buffer to the pool or is it still bound to the instance? What happens in case of the .swap()-trick? Regards, Daniel -- Daniel Frey aixigo AG - financial solutions & technology Schloß-Rahe-Straße 15, 52072 Aachen, Germany fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99 eMail: daniel.frey@aixigo.de, web: http://www.aixigo.de

On Tue, Jul 06, 2004 at 04:53:38PM +0100, jhopkin@reflectionsinteractive.com wrote:
Daniel Frey wrote:
Gennaro Prota wrote:
Does the swap trick necessarily free the memory?
AFAIK, yes. See <http://www.gotw.ca/gotw/054.htm>.
The STL implementation I have been using seems to allocate a buffer on first insertion into any container of a given type, and frees it only when it feels like it (often on program shut-down).
The swap trick will free the memory used by the container. What "free the memory" means in this case is implementation-defined. If the impl'n uses a memory pool (as GCC's libstdc++ does) then the memory will be returned to the pool. Returning the memory to the OS is a different matter. With libstdc++ you can disable the pool allocator, so that all allocations are done using "new", and so deallocations will return the memory to the OS. I would assume other pool-based allocators offer a similar feature. jon -- "Sell your cleverness and buy bewilderment: Cleverness is mere opinion, bewilderment is intuition." - Jalal-uddin Rumi
participants (3)
-
Daniel Frey
-
jhopkin@reflectionsinteractive.com
-
Jonathan Wakely