_info 1.6 KB

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