получили ускорение в 42 раза по сравнению с malloc и в 56 раз по сравнению с vector_add
This commit is contained in:
parent
b8d84794f0
commit
58d938d391
@ -6,8 +6,10 @@ int main()
|
|||||||
{
|
{
|
||||||
unsigned long long i;
|
unsigned long long i;
|
||||||
|
|
||||||
|
void *p = NULL;
|
||||||
|
|
||||||
for (i = 0; i < MAX_I; i++)
|
for (i = 0; i < MAX_I; i++)
|
||||||
free(malloc(1));
|
p = malloc(1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -53,32 +53,18 @@ inline void *alloc()
|
|||||||
if (!free_pool)
|
if (!free_pool)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
struct block_s *f1 = free_pool,
|
if (busy_pool) {
|
||||||
*f2 = free_pool->next,
|
free_pool->next = busy_pool;
|
||||||
*b1 = busy_pool;
|
busy_pool->prev = free_pool;
|
||||||
|
|
||||||
// move one free block to busy list
|
|
||||||
|
|
||||||
// f1, b1
|
|
||||||
if (b1) {
|
|
||||||
f1->next = b1;
|
|
||||||
b1->prev = f1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
f1->next = NULL;
|
free_pool->next = NULL;
|
||||||
|
|
||||||
// f2
|
busy_pool = free_pool;
|
||||||
if (f2)
|
|
||||||
f2->prev = NULL;
|
|
||||||
|
|
||||||
// free_pool
|
free_pool = free_pool->next;
|
||||||
free_pool = f2;
|
|
||||||
|
|
||||||
// busy_pool
|
return &busy_pool->obj;
|
||||||
busy_pool = f1;
|
|
||||||
|
|
||||||
|
|
||||||
return &f1->obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void free(void *p)
|
inline void free(void *p)
|
||||||
|
@ -9,5 +9,5 @@ c++ -O2 vector_add.cpp -o vector_add && time ./vector_add
|
|||||||
echo -e "\n\npool1.c test:"
|
echo -e "\n\npool1.c test:"
|
||||||
cc -O2 pool1.c -o pool1 && time ./pool1
|
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
|
cc -O2 pool_list.c -o pool_list && time ./pool_list
|
||||||
|
Loading…
x
Reference in New Issue
Block a user