получили ускорение в 42 раза по сравнению с malloc и в 56 раз по сравнению с vector_add

This commit is contained in:
Kolan Sh 2011-04-29 16:00:49 +04:00
parent b8d84794f0
commit 58d938d391
3 changed files with 11 additions and 23 deletions

View File

@ -6,8 +6,10 @@ int main()
{
unsigned long long i;
void *p = NULL;
for (i = 0; i < MAX_I; i++)
free(malloc(1));
p = malloc(1);
return 0;
}

View File

@ -53,32 +53,18 @@ inline void *alloc()
if (!free_pool)
return NULL;
struct block_s *f1 = free_pool,
*f2 = free_pool->next,
*b1 = busy_pool;
// move one free block to busy list
// f1, b1
if (b1) {
f1->next = b1;
b1->prev = f1;
if (busy_pool) {
free_pool->next = busy_pool;
busy_pool->prev = free_pool;
}
else
f1->next = NULL;
free_pool->next = NULL;
// f2
if (f2)
f2->prev = NULL;
// free_pool
free_pool = f2;
busy_pool = free_pool;
// busy_pool
busy_pool = f1;
free_pool = free_pool->next;
return &f1->obj;
return &busy_pool->obj;
}
inline void free(void *p)

View File

@ -9,5 +9,5 @@ c++ -O2 vector_add.cpp -o vector_add && time ./vector_add
echo -e "\n\npool1.c test:"
cc -O2 pool1.c -o pool1 && time ./pool1
echo -e "\n\npool_list.c test:"
echo -e "\n\npool_list.c test (вычесть 279мс на init()):"
cc -O2 pool_list.c -o pool_list && time ./pool_list