wangzhengquan
2020-07-27 554529bb69cd610e83db2c9a80b4f36f5225d80f
src/queue/include/mem_pool.h
@@ -34,6 +34,22 @@
   return ptr;
}
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 (void *ptr) {
   mm_free(ptr);
   // notify malloc
@@ -45,10 +61,12 @@
   return mm_realloc(ptr, size);
}
static inline hashtable_t * mem_pool_get_hashtable() {
   return mm_get_hashtable();
static inline int mem_pool_alloc_key() {
   hashtable_t *hashtable = mm_get_hashtable();
   return hashtable_alloc_key(hashtable);
}
// extern int mm_checkheap(int verbose);