]> git.ozlabs.org Git - ccan/blob - ccan/block_pool/_info
Merge.
[ccan] / ccan / block_pool / _info
1 #include <stdio.h>
2 #include <string.h>
3 #include "config.h"
4
5 /**
6  * block_pool - An efficient allocator for blocks that don't need to be
7  * resized or freed.
8  *
9  * block_pool allocates blocks by packing them into buffers, making the
10  * overhead per block virtually zero.  Because of this, you cannot resize or
11  * free individual blocks, but you can free the entire block_pool.
12  *
13  * The rationale behind block_pool is that talloc uses a lot of bytes per
14  * block (48 on 32-bit, 80 on 64-bit).  Nevertheless, talloc is an excellent
15  * tool for C programmers of all ages.  Because a block_pool is a talloc
16  * context, it can be useful in talloc-based applications where many small
17  * blocks need to be allocated.
18  *
19  * Example:
20  *
21  * #include <ccan/block_pool/block_pool.h>
22  *
23  * int main(void) {
24  *      struct block_pool *bp = block_pool_new(NULL);
25  *
26  *      void *buffer = block_pool_alloc(bp, 4096);
27  *      char *string = block_pool_strdup(bp, "A string");
28  *
29  *      int array[] = {0,1,1,2,3,5,8,13,21,34};
30  *      int *array_copy = block_pool_memdup(bp, array, sizeof(array));
31  *
32  *      block_pool_free(bp);
33  *    return 0;
34  * }
35  *
36  *      Author: Joey Adams
37  *      License: BSD
38  */
39 int main(int argc, char *argv[])
40 {
41         /* Expect exactly one argument */
42         if (argc != 2)
43                 return 1;
44
45         if (strcmp(argv[1], "depends") == 0) {
46                 printf("ccan/talloc\n");
47                 return 0;
48         }
49
50         return 1;
51 }