src/mempool.c

changeset 962
cd418898af5c
parent 947
2a47b4a5c216
equal deleted inserted replaced
961:bc8b7c5f55fb 962:cd418898af5c
95 95
96 if (newm == NULL) { 96 if (newm == NULL) {
97 return NULL; 97 return NULL;
98 } 98 }
99 if (mem != newm) { 99 if (mem != newm) {
100 cx_for_n(i, pool->size) { 100 for (size_t i = 0; i < pool->size; i++) {
101 if (pool->data[i] == mem) { 101 if (pool->data[i] == mem) {
102 pool->data[i] = newm; 102 pool->data[i] = newm;
103 return ((char*)newm) + sizeof(cx_destructor_func); 103 return ((char*)newm) + sizeof(cx_destructor_func);
104 } 104 }
105 } 105 }
117 struct cx_mempool_s *pool = p; 117 struct cx_mempool_s *pool = p;
118 118
119 struct cx_mempool_memory_s *mem = (struct cx_mempool_memory_s *) 119 struct cx_mempool_memory_s *mem = (struct cx_mempool_memory_s *)
120 ((char *) ptr - sizeof(cx_destructor_func)); 120 ((char *) ptr - sizeof(cx_destructor_func));
121 121
122 cx_for_n(i, pool->size) { 122 for (size_t i = 0; i < pool->size; i++) {
123 if (mem == pool->data[i]) { 123 if (mem == pool->data[i]) {
124 if (mem->destructor) { 124 if (mem->destructor) {
125 mem->destructor(mem->c); 125 mem->destructor(mem->c);
126 } 126 }
127 free(mem); 127 free(mem);
137 abort(); 137 abort();
138 } 138 }
139 139
140 void cxMempoolDestroy(CxMempool *pool) { 140 void cxMempoolDestroy(CxMempool *pool) {
141 struct cx_mempool_memory_s *mem; 141 struct cx_mempool_memory_s *mem;
142 cx_for_n(i, pool->size) { 142 for (size_t i = 0; i < pool->size; i++) {
143 mem = pool->data[i]; 143 mem = pool->data[i];
144 if (mem->destructor) { 144 if (mem->destructor) {
145 mem->destructor(mem->c); 145 mem->destructor(mem->c);
146 } 146 }
147 free(mem); 147 free(mem);

mercurial