/* * Copyright (c) 2020 YuQing <384681@qq.com> * * This program is free software: you can use, redistribute, and/or modify * it under the terms of the Lesser GNU General Public License, version 3 * or later ("LGPL"), as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the Lesser GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include "fastcommon/logger.h" #include "fastcommon/shared_func.h" #include "fastcommon/sched_thread.h" #include "fastcommon/ini_file_reader.h" #include "fastcommon/fast_allocator.h" #define OUTER_LOOP_COUNT 128 #define INNER_LOOP_COUNT 1024 * 64 #define USE_ALLOCATOR 1 #if USE_ALLOCATOR == 1 #define MALLOC(bytes) fast_allocator_alloc(&acontext, bytes) #define FREE(ptr) fast_allocator_free(&acontext, ptr) #else #define MALLOC(bytes) malloc(bytes) #define FREE(ptr) free(ptr) #endif int main(int argc, char *argv[]) { int result; struct fast_allocator_context acontext; void *ptrs[INNER_LOOP_COUNT]; int bytes; int i; int k; int64_t start_time; printf("use allocator: %d\n", USE_ALLOCATOR); start_time = get_current_time_ms(); log_init(); srand(time(NULL)); g_log_context.log_level = LOG_DEBUG; fast_mblock_manager_init(); if ((result=fast_allocator_init(&acontext, NULL, 0, 0.00, 0, true)) != 0) { return result; } fast_mblock_manager_stat_print(true); for (k=0; k