]> git.ozlabs.org Git - ccan/blob - ccan/block_pool/_info
block_pool, ccan_tokenizer, stringmap: add ccanlint license suppressions.
[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 resized or freed.
7  *
8  * block_pool allocates blocks by packing them into buffers, making the
9  * overhead per block virtually zero.  Because of this, you cannot resize or
10  * free individual blocks, but you can free the entire block_pool.
11  *
12  * The rationale behind block_pool is that talloc uses a lot of bytes per
13  * block (48 on 32-bit, 80 on 64-bit).  Nevertheless, talloc is an excellent
14  * tool for C programmers of all ages.  Because a block_pool is a talloc
15  * context, it can be useful in talloc-based applications where many small
16  * blocks need to be allocated.
17  *
18  * Example:
19  *
20  * #include <ccan/block_pool/block_pool.h>
21  *
22  * int main(void) {
23  *      struct block_pool *bp = block_pool_new(NULL);
24  *
25  *      void *buffer = block_pool_alloc(bp, 4096);
26  *      char *string = block_pool_strdup(bp, "A string");
27  *
28  *      int array[] = {0,1,1,2,3,5,8,13,21,34};
29  *      int *array_copy = block_pool_memdup(bp, array, sizeof(array));
30  *
31  *      memset(buffer, 0xff, 4096);
32  *      printf("string = %s\n", string);
33  *      printf("array_copy[0] == %i\n", array_copy[0]);
34  *      block_pool_free(bp);
35  *    return 0;
36  * }
37  *
38  * Author: Joey Adams <joeyadams3.14159@gmail.com>
39  * License: MIT
40  * Version: 0.1
41  * Ccanlint:
42  *      // We actually depend on the LGPL talloc
43  *      license_depends_compat FAIL
44  */
45 int main(int argc, char *argv[])
46 {
47         /* Expect exactly one argument */
48         if (argc != 2)
49                 return 1;
50
51         if (strcmp(argv[1], "depends") == 0) {
52                 printf("ccan/talloc\n");
53                 return 0;
54         }
55
56         return 1;
57 }