73 memset(ptr, 0, nelem * elsize); |
73 memset(ptr, 0, nelem * elsize); |
74 return ptr; |
74 return ptr; |
75 } |
75 } |
76 |
76 |
77 void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n) { |
77 void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n) { |
78 void *mem = ((char*)ptr) - sizeof(ucx_destructor); |
78 char *mem = ((char*)ptr) - sizeof(ucx_destructor); |
79 char *newm = (char*) realloc(mem, n + sizeof(ucx_destructor)); |
79 char *newm = (char*) realloc(mem, n + sizeof(ucx_destructor)); |
80 if (newm == NULL) return NULL; |
80 if (newm == NULL) return NULL; |
81 if (mem != newm) { |
81 if (mem != newm) { |
82 for(int i=0;i<pool->ndata;i++) { |
82 for(int i=0;i<pool->ndata;i++) { |
83 if(pool->data[i] == mem) { |
83 if(pool->data[i] == mem) { |
84 pool->data[i] = newm; |
84 pool->data[i] = newm; |
85 return ((char*) newm) + sizeof(ucx_destructor); |
85 return newm + sizeof(ucx_destructor); |
86 } |
86 } |
87 } |
87 } |
88 fprintf(stderr, "FATAL: %8x not in mpool %8x\n", mem, pool); |
88 fprintf(stderr, "FATAL: %8x not in mpool %8x\n", ptr, pool); |
89 exit(1); |
89 exit(1); |
90 } else { |
90 } else { |
91 return ((char*) newm) + sizeof(ucx_destructor); |
91 return newm + sizeof(ucx_destructor); |
92 } |
92 } |
93 } |
93 } |
94 |
94 |
95 void ucx_mempool_free(UcxMempool *pool) { |
95 void ucx_mempool_free(UcxMempool *pool) { |
96 ucx_memchunk *chunk; |
96 ucx_memchunk *chunk; |