Efficient per-class allocator
Consider the following g++ code:
#include "../../2006/nogc2/global.hh"
class Foo
{
int data;
};
extern Foo* create();
extern void func();
extern void test1(int ILEN);
extern void test2(int ILEN);
int main()
{
allegro_init_first_windowed(640,480);
const int len = 1000 * 1000;
retrace_count = 0;
test1(len);
int time_create = retrace_count;
retrace_count = 0;
test2(len);
int time_none = retrace_count;
textout(screen,font,(string() + "time1=" +
time_create).const_char_star(),0,0,allegro_col_white);
textout(screen,font,(string() + "time2=" +
time_none).const_char_star(),0,8,allegro_col_white);
readkey();
return EXIT_SUCCESS;
}
END_OF_MAIN();
void func()
{
}
Foo* create()
{
return new Foo();
}
void test1(const int ILEN)
{
for (int i=0; i<ILEN; i++)
{
Foo* f = create();
delete f;
}
}
void test2(const int ILEN)
{
for (int i=0; i<ILEN; i++)
{
func();
func();
}
}
Apologies for the lack of standard code in the main function. I am
using the Allegro graphics library and my own string class. The rest
of the code is portable however. When I run the above code, it says
that the call to test1(1000 * 1000) takes 29 / 70 seconds and the call
to test2(1000 * 1000) takes 1 / 70 seconds. I would like to find a
per-class allocator that uses linked lists to provide performance that
takes as long as the call to test2 takes.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]