测试内存池
This commit is contained in:
@@ -5,13 +5,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
|
||||
// #define MEMPOOL_PAGE_SIZE 4096
|
||||
#define MEMPOOL_PAGE_SIZE (1024*8)
|
||||
#define MEMPOOL_PAGE_SIZE (4096*2)
|
||||
#define MEMPOOL_BLOCK_MAX_SIZE 512
|
||||
#define MEMPOOL_ALIGNMENT 8
|
||||
#define MEMPOOL_NUM_CLASSES (MEMPOOL_BLOCK_MAX_SIZE / MEMPOOL_ALIGNMENT)
|
||||
#define MEMPOOL_CACHE_PAGE 4
|
||||
#define MEMPOOL_CACHE_PAGE 2
|
||||
|
||||
typedef struct mp_page_s mp_page_t;
|
||||
typedef struct mp_bucket_s mp_bucket_t;
|
||||
@@ -35,7 +36,7 @@ struct mp_page_s{
|
||||
uint16_t free_count;
|
||||
uint16_t capacity;
|
||||
|
||||
uint64_t bitmap[20]; // 最多支持 512/1280 个块 (64*20)
|
||||
uint64_t bitmap[16]; // 最多支持 512/1280 个块 (64*20)
|
||||
};
|
||||
|
||||
struct mp_bucket_s{
|
||||
@@ -56,7 +57,7 @@ struct mp_large_s{
|
||||
struct mp_pool_s{
|
||||
mp_bucket_t buckets[MEMPOOL_NUM_CLASSES];
|
||||
|
||||
mp_large_t *large_list;
|
||||
mp_large_t *large_list;
|
||||
};
|
||||
|
||||
int mp_create(mp_pool_t *pool);
|
||||
@@ -65,4 +66,6 @@ int mp_destroy(mp_pool_t *pool);
|
||||
void *mp_alloc(mp_pool_t *pool, size_t size);
|
||||
int mp_free(mp_pool_t *pool, void *ptr);
|
||||
|
||||
int mp_print(mp_pool_t *pool);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user