Re: Virtual Bytes is STL
anand chugh wrote:
Although SGI is having more allocators than default one but microsoft
support only default and we have to implement our own to support this
behaviour.
FYI, you can use e.g. STLport, which is a complete replacement for the
native stdlib and also has several allocators. Further, I think that Boost
has some allocators, so you don't necessarily have to roll your own.
My main point is if in a program I have allocated vector of 5000
strings and after some time I have freed the vector then in no way
program should keep that memory for future uses.If that program is a
service then it will keep that memory forever until its not stopped or
computer is not shut down.That is not what I expected from STL.
By default behaviour should be , as soon as vector is cleared its
memory should be free. If I want to allocate memory for that vector I
will call reserve again.
Does it not make sense?
It depends on what you expect. As far as a service on e.g. a server or a
workstation is concerned, those typically have enough virtual memory to be
able to ignore this issue normally. Maybe some of the memory is swapped to
disk, but it doesn't block RAM which is more important.
Of course, if you e.g. parse things, you often have the case that you need
lots of memory and eventually release all of it and never need it again. In
such cases a pool allocator could be of help.
For the general case, the default behaviour is good though, because giving
back all memory to the OS is a time-intensive task. You might want to limit
the amount of reserved memory, but you probably don't want to limit it to
zero.
good luck
Uli