(making pools aligned by default). Added the missing code to make the
documented behavior of pool_free() with a NULL addr work. Updated the
pool_alloc.3 manpage.
if (flags & FLIST_TEMP) {
if (!(flist->file_pool = pool_create(SMALL_EXTENT, 0,
out_of_memory,
if (flags & FLIST_TEMP) {
if (!(flist->file_pool = pool_create(SMALL_EXTENT, 0,
out_of_memory,
- POOL_INTERN|POOL_QALIGN)))
out_of_memory(msg);
} else {
/* This is a doubly linked list with prev looping back to
out_of_memory(msg);
} else {
/* This is a doubly linked list with prev looping back to
if (!first_flist) {
flist->file_pool = pool_create(NORMAL_EXTENT, 0,
out_of_memory,
if (!first_flist) {
flist->file_pool = pool_create(NORMAL_EXTENT, 0,
out_of_memory,
- POOL_INTERN|POOL_QALIGN);
if (!flist->file_pool)
out_of_memory(msg);
if (!flist->file_pool)
out_of_memory(msg);
.I quantum
will produce a quantum that should meet maximal alignment
on most platforms.
.I quantum
will produce a quantum that should meet maximal alignment
on most platforms.
+Unless
+.B POOL_NO_QALIGN
is set in the
.IR flags ,
allocations will be aligned to addresses that are a
multiple of
.IR quantum .
is set in the
.IR flags ,
allocations will be aligned to addresses that are a
multiple of
.IR quantum .
+A
+.B NULL
+may be specified for the
+.I bomb
+function pointer if it is not needed. (See the
+.B pool_alloc()
+function for how it is used.)
If
.B POOL_CLEAR
is set in the
.IR flags ,
all allocations from the pool will be initialized to zeros.
If
.B POOL_CLEAR
is set in the
.IR flags ,
all allocations from the pool will be initialized to zeros.
-You may specify a
-.B NULL
-for the
-.I bomb
-function pointer if you don't wish to use it. (See the
-.B pool_alloc()
-function for how it is used.)
+If either
+.B POOL_PREPEND
+or
+.B POOL_INTERN
+is specified in the
+.IR flags ,
+each extent's data structure will be allocated at the start of the
+.IR size -length
+buffer (rather than as a separate, non-pool allocation), with the
+former extending the
+.I size
+to hold the structure, and the latter subtracting the structure's
+length from the indicated
+.IR size .
.P
.B pool_destroy()
destroys an allocation
.P
.B pool_destroy()
destroys an allocation
.BR 0 ,
.I quantum
bytes will be allocated.
.BR 0 ,
.I quantum
bytes will be allocated.
-If the pool has been created with
-.BR POOL_QALIGN ,
+If the pool has been created without
+.BR POOL_NO_QALIGN ,
every chunk of memory that is returned will be suitably aligned.
You can use this with the default
.I quantum
every chunk of memory that is returned will be suitably aligned.
You can use this with the default
.I quantum
no memory will be freed, but subsequent allocations will come
from a new extent.
.P
no memory will be freed, but subsequent allocations will come
from a new extent.
.P
#define POOL_DEF_EXTENT (32 * 1024)
#define POOL_DEF_EXTENT (32 * 1024)
-#define POOL_QALIGN_P2 (1<<16)
+#define POOL_QALIGN_P2 (1<<16) /* power-of-2 qalign */
- flags &= ~(POOL_QALIGN | POOL_QALIGN_P2);
- else if (flags & POOL_QALIGN) {
+ flags = (flags | POOL_NO_QALIGN) & ~POOL_QALIGN_P2;
+ else if (!(flags & POOL_NO_QALIGN)) {
if (size % quantum)
size += quantum - size % quantum;
/* If quantum is a power of 2, we'll avoid using modulus. */
if (size % quantum)
size += quantum - size % quantum;
/* If quantum is a power of 2, we'll avoid using modulus. */
else if (pool->flags & POOL_QALIGN_P2) {
if (len & (pool->quantum - 1))
len += pool->quantum - (len & (pool->quantum - 1));
else if (pool->flags & POOL_QALIGN_P2) {
if (len & (pool->quantum - 1))
len += pool->quantum - (len & (pool->quantum - 1));
- } else if (pool->flags & POOL_QALIGN) {
+ } else if (!(pool->flags & POOL_NO_QALIGN)) {
if (len % pool->quantum)
len += pool->quantum - len % pool->quantum;
}
if (len % pool->quantum)
len += pool->quantum - len % pool->quantum;
}
+ if (!addr) {
+ /* A NULL addr starts a fresh extent for new allocations. */
+ if ((cur = pool->extents) != NULL && cur->free != pool->size) {
+ cur->bound += cur->free;
+ cur->free = 0;
+ }
+ return;
+ }
+
if (!len)
len = pool->quantum;
else if (pool->flags & POOL_QALIGN_P2) {
if (len & (pool->quantum - 1))
len += pool->quantum - (len & (pool->quantum - 1));
if (!len)
len = pool->quantum;
else if (pool->flags & POOL_QALIGN_P2) {
if (len & (pool->quantum - 1))
len += pool->quantum - (len & (pool->quantum - 1));
- } else if (pool->flags & POOL_QALIGN) {
+ } else if (!(pool->flags & POOL_NO_QALIGN)) {
if (len % pool->quantum)
len += pool->quantum - len % pool->quantum;
}
if (len % pool->quantum)
len += pool->quantum - len % pool->quantum;
}
#include <stddef.h>
#define POOL_CLEAR (1<<0) /* zero fill allocations */
#include <stddef.h>
#define POOL_CLEAR (1<<0) /* zero fill allocations */
-#define POOL_QALIGN (1<<1) /* align data to quanta */
+#define POOL_NO_QALIGN (1<<1) /* don't align data to quanta */
#define POOL_INTERN (1<<2) /* Allocate extent structures */
#define POOL_PREPEND (1<<3) /* or prepend to extent data */
#define POOL_INTERN (1<<2) /* Allocate extent structures */
#define POOL_PREPEND (1<<3) /* or prepend to extent data */