From 58d938d3910598831ca7b0aa14685374582722c6 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Fri, 29 Apr 2011 16:00:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B8=D0=BB?= =?UTF-8?q?=D0=B8=20=D1=83=D1=81=D0=BA=D0=BE=D1=80=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=B2=2042=20=D1=80=D0=B0=D0=B7=D0=B0=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8=D1=8E=20=D1=81?= =?UTF-8?q?=20malloc=20=D0=B8=20=D0=B2=2056=20=D1=80=D0=B0=D0=B7=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8=D1=8E?= =?UTF-8?q?=20=D1=81=20vector=5Fadd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- c/malloc_speed_test/malloc_speed_test.c | 4 +++- c/malloc_speed_test/pool_list.c | 28 +++++++------------------ c/malloc_speed_test/run.sh | 2 +- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/c/malloc_speed_test/malloc_speed_test.c b/c/malloc_speed_test/malloc_speed_test.c index f812ab1..f9259fd 100644 --- a/c/malloc_speed_test/malloc_speed_test.c +++ b/c/malloc_speed_test/malloc_speed_test.c @@ -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; } diff --git a/c/malloc_speed_test/pool_list.c b/c/malloc_speed_test/pool_list.c index 651240d..fa1f42a 100644 --- a/c/malloc_speed_test/pool_list.c +++ b/c/malloc_speed_test/pool_list.c @@ -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) diff --git a/c/malloc_speed_test/run.sh b/c/malloc_speed_test/run.sh index e153157..5b60411 100755 --- a/c/malloc_speed_test/run.sh +++ b/c/malloc_speed_test/run.sh @@ -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