| | |
| | | // 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); |
| | | // 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); |
| | | // 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) { |
| | | void *ptr; |
| | | // T* tptr; |
| | | hashtable_t *hashtable = mm_get_hashtable(); |
| | | ptr = hashtable_get(hashtable, key); |
| | | if(ptr != NULL) { |
| | | mm_free(ptr); |
| | | hashtable_remove(hashtable, key); |
| | | } |
| | | } |
| | | |
| | | static inline void mem_pool_free (void *ptr) { |
| | | mm_free(ptr); |
| | | // notify malloc |