From: xushiwei on
{ See the FAQ about top-posting. Please do not top-post in clc++m. -mod }


1. Do you test the performance of your allocator? If not, try to
download mine and do a comparison:

# Download from Boost Vault or http://code.google.com/p/stdext/downloads/list.
# Svn checkout http://winx.googlecode.com/svn/tags/boost-memory-0.1.00/.
# Svn checkout http://svn.boost.org/svn/boost/sandbox/memory/.

Test case is available here:
http://svn.boost.org/svn/boost/sandbox/memory/libs/memory/test/test_basic/memory/performance.cpp

2. Your allocator don't call destructor of an object (of course, it is
not a emphasis since it is easy to be added).

> Had a look at your code... Looks unnecessarily complicated to me. Here
> is the result of about 15 minutes of work:
>
> [code]
> #include <deque>
> #include <cassert>
>
> using namespace std;
>
> struct FastAlloc
> {
> struct Block
> {
> unsigned char memory[1024];
> };
> deque<Block> m_pool;
> size_t m_left;
>
> FastAlloc() : m_left(0) {}
>
> void* allocate(size_t size)
> {
> assert(size <= 1024);
> if (size > m_left)
> {
> m_pool.resize(m_pool.size() + 1);
> m_left = 1024;
> }
>
> void* res = m_pool.back().memory + 1024 - m_left;
> m_left -= size;
> return res;
> }
>
> };
>
> int main()
> {
> FastAlloc alloc;
>
> deque<int, my_alloc<int> > q(alloc);
>
> q.push_back(1024);
> return 1;}
>
> [/code]
>
> add STD_NEW/STD_DELETE support, parametrize my_alloc with allocator
> type, write few different allocator classes and that's it. Looks much
> more simple.
>
> Sincerely yours,
> Michael.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]