|
Boost : |
From: Michael Andersen Nexø (nexo_at_[hidden])
Date: 2001-03-01 12:50:31
Daryle,
Recently, I've implemented a generic suballocator that I think would fit
nicely into your memory utilities library. Below is a (somewhat long)
description of it. Anyone, please let me know if it might be of interest to
include it in the Boost library. If you have comments, please don't hesitate
to mail me or the boost-list.
Although it is not yet thoroughly tested, I will gladly upload the code for
all of you to inspect, but, alas, I have yet to learn how to do that.
Thank you,
Michael Andersen Nexø
==================================================================
template <class Allocator> class suballocator;
This template defines a suballocator that functions as an intermediate layer
between a inefficiently implemented allocator and a C++ Standard Library
container.
A typical "real world" situation is to have some kind of low-level memory
allocation routines provided by the run-time environment. Unfortunately,
such routines are often crippled by unacceptable space/time overheads for
allocations of smaller objects, hereby rendering a naive implementation of
an allocator for use with the Standard Library Containers very ineffective.
suballocator remedies this problem by implementing an efficient
suballocation strategy on top of the naive allocator implementation.
The interface of the suballocator itself conforms to the requirements of the
Standard Library Containers, provided that the underlying allocator does so.
Example:
--------
Suppose that for some reason the environment dictates that heap allocations
must be made by the functions 'SlowMalloc()' and 'SlowFree()':
1) Define a naive allocator, 'slow_allocator', by simply calling
SlowMalloc(n)/SlowFree(p) in allocate(n,hint) and deallocate(p,n). E.g.:
template <class T> class slow_allocator
{
public:
// ... typical typedefs, constructors, rebind struct, etc. here...
T* allocate(size_type n, void* hint = 0) { return ::SlowMalloc(n); }
void deallocate(pointer p, size_type n) { ::SlowFree(p); }
size_type max_size() const { return ::SlowAvailSpace(n)/sizeof(T); }
};
2)suballocator<slow_allocator<int>, 1000> will now define an allocator
that efficiently allocates ints from SlowMalloc in pools of 1000 bytes
or more at a time. E.g.:
typedef suballocator<slow_allocator<int>, 1000> > int_allocator;
std::list<int, int_allocator> fast_list;
// Or: (we're in dire need of template typedefs here!)
template <class T>
class fast_allocator : public suballocator<slow_allocator<int>, 1000>{};
std::vector<int, fast_allocator<int> > fast_vec;
----- Original Message -----
From: <boost_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, March 01, 2001 12:32 AM
Subject: [boost] New file uploaded to boost
>
> Hello,
>
> This email message is a notification to let you know that
> a file has been uploaded to the Files area of the boost
> group.
>
> File : /memory.zip
> Uploaded by : darylew_at_[hidden]
> Description : Version 1; auto_ary and other memory utilities
>
> You can access this file at the URL
>
> http://groups.yahoo.com/group/boost/files/memory.zip
>
> To learn more about file sharing for your group, please visit
>
> http://help.yahoo.com/help/us/groups/files
>
> Regards,
>
> darylew_at_[hidden]
>
>
>
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk