Re: C++ Memory Management Innovation: GC Allocator
Home
FAQ
Contact
Sign in
Search
comp.lang.c++.moderated only
Advanced search
POPULAR GROUPS
perl.cpan.testers
alt.bestjobsusa.computer
alt.bestjobsusa.computer.jobs
us.jobs
us.jobs.offered
alt.bestjobsusa.jobs.offered
news.admin.netabuse.sightings
alt.politics
it.politica
alt.fan.rushlimbaugh
more...
Up
Re: C++ Memory Management Innovation: GC Allocator
Group:
comp.lang.c++.moderated
·
Group Profile
Author:
xushiwei
xushiwei
Date:
May 7, 2008 09:10
{ 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...
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
> #include
>
> using namespace std;
>
> struct FastAlloc
> {
> struct Block
> {
> unsigned char memory[1024];
> };
> deque
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
> 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! ]
no comments
diggit!
del.icio.us!
reddit!