73 return NULL; |
73 return NULL; |
74 } |
74 } |
75 |
75 |
76 pool->ndata = 0; |
76 pool->ndata = 0; |
77 pool->size = n; |
77 pool->size = n; |
|
78 |
|
79 UcxAllocator *allocator = (UcxAllocator*)malloc(sizeof(UcxAllocator)); |
|
80 if(!allocator) { |
|
81 free(pool->data); |
|
82 free(pool); |
|
83 return NULL; |
|
84 } |
|
85 allocator->malloc = (ucx_allocator_malloc)ucx_mempool_malloc; |
|
86 allocator->calloc = (ucx_allocator_calloc)ucx_mempool_calloc; |
|
87 allocator->realloc = (ucx_allocator_realloc)ucx_mempool_realloc; |
|
88 allocator->free = (ucx_allocator_free)ucx_mempool_free; |
|
89 allocator->pool = pool; |
|
90 pool->allocator = allocator; |
|
91 |
78 return pool; |
92 return pool; |
79 } |
93 } |
80 |
94 |
81 int ucx_mempool_chcap(UcxMempool *pool, size_t newcap) { |
95 int ucx_mempool_chcap(UcxMempool *pool, size_t newcap) { |
82 void **data = (void**) realloc(pool->data, newcap*sizeof(void*)); |
96 void **data = (void**) realloc(pool->data, newcap*sizeof(void*)); |
187 rd->destructor = destr; |
202 rd->destructor = destr; |
188 rd->ptr = ptr; |
203 rd->ptr = ptr; |
189 ucx_mempool_set_destr(rd, ucx_mempool_shared_destr); |
204 ucx_mempool_set_destr(rd, ucx_mempool_shared_destr); |
190 } |
205 } |
191 |
206 |
192 UcxAllocator* ucx_mempool_allocator(UcxMempool *pool) { |
|
193 UcxAllocator *allocator = (UcxAllocator*)ucx_mempool_malloc( |
|
194 pool, sizeof(UcxAllocator)); |
|
195 if(!allocator) { |
|
196 return NULL; |
|
197 } |
|
198 allocator->malloc = (ucx_allocator_malloc)ucx_mempool_malloc; |
|
199 allocator->calloc = (ucx_allocator_calloc)ucx_mempool_calloc; |
|
200 allocator->realloc = (ucx_allocator_realloc)ucx_mempool_realloc; |
|
201 allocator->free = (ucx_allocator_free)ucx_mempool_free; |
|
202 allocator->pool = pool; |
|
203 return allocator; |
|
204 } |
|