Topic: allocator requirements - are they too stringent?


Author: "news.w-link.net" <ongg@w-link.net>
Date: 2000/10/05
Raw View
Hi!

I want to write an allocator that, for the sake of efficiency, returns only
fixed-size memory locations.  However, the allocator requirements requires
allocate() to take in a numerical value that indicate the number of blocks
to allocate.

The way that I was planning on utilizing this class, I would never have any
need to call more than 1 block, and having it return a contiguous block of
more than size 1 would break the efficiency gains from this memory pool I'm
implementing.

Of course, I can have allocate(n), n>1, throw an exception, but that is not
the best way for things to go.

Are the allocator requirements too stringent? I can see value in having a
function like:
allocator::single_allocate(const_pointer hint = 0);

This way, fixed-sized allocators can be created, and those containers that
only allocate one block at a time (list) can make use of it while those
containers that require large allocation blocks (vector) can use
allocator::allocate()

Ideas? Thoughts?

Thanks!
Jay


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]