[Exceptional C++ Style] Item 20: Containers in Memory, Part 1: Levels of Memory Management.

Paul Grenyer paul at paulgrenyer.co.uk
Mon Jan 10 12:30:19 EST 2005


Memory Managers and Their Strategies: A brief summary
-----------------------------------------------------

Memory Managers, also known as memory allocates, are used to allocate memory
for containers. There are a number of different memory management strategies
available, two popular ones are:

 - General-purpose allocation can provide any size of memory block that a
caller might request (the request size, or block size). General-purpose
allocation is very flexible but has several drawbacks, two of which are:

1) Performance, because it has more work to do
2) Fragmentation , because as blocks are allocated and freed we can end up
with lots of little non-contiguous areas of unallocated memory

 - Fixed-size allocation always returns a block of the same fixed size. This
is obviously less flexible than general purpose allocation, but it can be
done much faster and doesn't result in the same kind of fragmentation.


Plotting Strategy
-----------------

The operating system kernel provides the most basic memory allocation
services. Different operating systems have different strategies and also
take into account the particular hardware they are running on.

The compiler's default runtime library builds its allocation services, such
as C++ operator new and C's malloc, upon the native allocation services.

The standard containers and allocators in turn use the compiler's services
and possibly further override them to implement their own strategies and
optimizations.

Finally, user-defined containers and/or user-defined allocators can further
reuse any lower-level of services and do pretty much whatever they please.

Guideline: Know who does what: Understand the actual (and system-dependant)
allocation strategies and responsibilities of your platform and standard
library.




Regards
Paul

Paul Grenyer
email: paul at paulgrenyer.co.uk
web: http://www.paulgrenyer.co.uk
articles: http://www.paulgrenyer.dyndns.org/articles/

"I don't need tv, when I've got t-rex..."





More information about the Effective-cpp mailing list