From f0732bbcbdca67ef8f9444f2aafaf44da81c9e5a Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期六, 01 八月 2020 16:44:00 +0800
Subject: [PATCH] update
---
src/queue/include/mem_pool.h | 31 ++++++++++++++++++++++++++++---
1 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/src/queue/include/mem_pool.h b/src/queue/include/mem_pool.h
index 17a7c5c..2ea1f6b 100644
--- a/src/queue/include/mem_pool.h
+++ b/src/queue/include/mem_pool.h
@@ -34,6 +34,7 @@
return ptr;
}
+
static inline void mem_pool_free (void *ptr) {
mm_free(ptr);
// notify malloc
@@ -41,14 +42,38 @@
}
+
+template <typename T>
+static inline T* mem_pool_attach(int key) {
+ void *ptr;
+ // T* tptr;
+ hashtable_t *hashtable = mm_get_hashtable();
+ ptr = hashtable_get(hashtable, key);
+// printf("mem_pool_malloc_by_key malloc before %d, %p\n", key, ptr);
+ if(ptr == NULL || ptr == (void *)1 ) {
+ ptr = mm_malloc(sizeof(T));
+ hashtable_put(hashtable, key, ptr);
+ new(ptr) T;
+// printf("mem_pool_malloc_by_key use new %d, %p\n", key, ptr);
+ }
+ return (T*)ptr;
+}
+
+static inline void mem_pool_free_by_key(int key) {
+ return mm_free_by_key(key);
+}
+
+
static inline void *mem_pool_realloc (void *ptr, size_t size) {
return mm_realloc(ptr, size);
}
-static inline hashtable_t * mem_pool_get_hashtable() {
- return mm_get_hashtable();
-
+static inline int mem_pool_alloc_key() {
+
+ return mm_alloc_key();
}
+
+
// extern int mm_checkheap(int verbose);
--
Gitblit v1.8.0