|
version 1.9, 2022/10/24 00:10:22
|
version 1.11, 2024/10/28 09:58:51
|
|
Line 12 terms:
|
Line 12 terms:
|
| All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
| Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
| |
|
| Copyright 2004 - 2022 | Copyright 2004 - 2024 |
| by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
| |
|
| Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
|
Line 91 mpool_init(u_long maxmem)
|
Line 91 mpool_init(u_long maxmem)
|
| void |
void |
| mpool_destroy(mpool_t ** __restrict mp) |
mpool_destroy(mpool_t ** __restrict mp) |
| { |
{ |
| struct tagAlloc *m; | struct tagAlloc *m, *n; |
| register int i; |
register int i; |
| |
|
| if (!mp && !*mp) | if (!mp || !*mp) |
| return; |
return; |
| |
|
| mpool_lock(*mp); |
mpool_lock(*mp); |
| |
|
| for (i = 0; i < MEM_BUCKETS; i++) { |
for (i = 0; i < MEM_BUCKETS; i++) { |
| while ((m = TAILQ_FIRST(&(*mp)->pool_active[i]))) { | for (m = TAILQ_FIRST(&(*mp)->pool_active[i]); m; m = n) { |
| TAILQ_REMOVE(&(*mp)->pool_active[i], m, alloc_node); | n = TAILQ_NEXT(m, alloc_node); |
| if (m->alloc_mem) |
if (m->alloc_mem) |
| free(m->alloc_mem); |
free(m->alloc_mem); |
| free(m); |
free(m); |
| } |
} |
| while ((m = TAILQ_FIRST(&(*mp)->pool_inactive[i]))) { | for (m = TAILQ_FIRST(&(*mp)->pool_inactive[i]); m; m = n) { |
| TAILQ_REMOVE(&(*mp)->pool_inactive[i], m, alloc_node); | n = TAILQ_NEXT(m, alloc_node); |
| if (m->alloc_mem) |
if (m->alloc_mem) |
| free(m->alloc_mem); |
free(m->alloc_mem); |
| free(m); |
free(m); |
|
Line 219 mpool_malloc(mpool_t * __restrict mp, u_int size, cons
|
Line 219 mpool_malloc(mpool_t * __restrict mp, u_int size, cons
|
| } else { /* quota */ |
} else { /* quota */ |
| mp->pool_quota.curr += size; |
mp->pool_quota.curr += size; |
| mp->pool_quota.real += 1 << (idx + MEM_MIN_BUCKET); |
mp->pool_quota.real += 1 << (idx + MEM_MIN_BUCKET); |
| |
#ifdef MPOOL_MEM_ZERO |
| memset(m->alloc_mem, 0, align + 12); |
memset(m->alloc_mem, 0, align + 12); |
| |
#endif |
| } |
} |
| } |
} |
| |
|
|
Line 236 mpool_malloc(mpool_t * __restrict mp, u_int size, cons
|
Line 238 mpool_malloc(mpool_t * __restrict mp, u_int size, cons
|
| } |
} |
| |
|
| /* |
/* |
| |
* mpool_calloc() - Multiple memory block allocation |
| |
* |
| |
* @mp = Memory pool |
| |
* @nmemb = Number of memory blocks |
| |
* @size = Size |
| |
* @memname = Optional memory block name |
| |
* return: NULL error or !=NULL ok allocated memory |
| |
*/ |
| |
void * |
| |
mpool_calloc(mpool_t * __restrict mp, u_int nmemb, u_int size, const char *memname) |
| |
{ |
| |
void *m; |
| |
u_int total = nmemb * size; |
| |
|
| |
m = mpool_malloc(mp, total, memname); |
| |
#ifndef MPOOL_MEM_ZERO |
| |
if (m) |
| |
memset(m, 0, total); |
| |
#endif |
| |
return m; |
| |
} |
| |
|
| |
/* |
| * mpool_realloc() Reallocate memory block with new size |
* mpool_realloc() Reallocate memory block with new size |
| * |
* |
| * @mp = Memory pool |
* @mp = Memory pool |
|
Line 293 mpool_realloc(mpool_t * __restrict mp, void * __restri
|
Line 318 mpool_realloc(mpool_t * __restrict mp, void * __restri
|
| |
|
| memcpy(p, data, MIN(osize, newsize)); |
memcpy(p, data, MIN(osize, newsize)); |
| mpool_free(mp, data, 0); |
mpool_free(mp, data, 0); |
| data = p; |
|
| } else { |
} else { |
| p = data; |
p = data; |
| |
|
|
Line 668 mpool_xmalloc(size_t size)
|
Line 692 mpool_xmalloc(size_t size)
|
| void * |
void * |
| mpool_xcalloc(size_t num, size_t size) |
mpool_xcalloc(size_t num, size_t size) |
| { |
{ |
| return mpool_malloc(elwix_mpool, num * size, elwix_Prog); | return mpool_calloc(elwix_mpool, num, size, elwix_Prog); |
| } |
} |
| |
|
| /* |
/* |