diff options
Diffstat (limited to 'src/pool.h')
| -rw-r--r-- | src/pool.h | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/pool.h b/src/pool.h index 5f65412a0..a92589087 100644 --- a/src/pool.h +++ b/src/pool.h @@ -33,11 +33,14 @@ typedef struct { void *free_list; /* optional: list of freed blocks */ uint32_t item_size; /* size of single alloc unit in bytes */ uint32_t page_size; /* size of page in bytes */ + uint32_t items; unsigned has_string_alloc : 1; /* was the strdup function used */ unsigned has_multi_item_alloc : 1; /* was items ever > 1 in malloc */ unsigned has_large_page_alloc : 1; /* are any pages > page_size */ } git_pool; +#define GIT_POOL_INIT_STRINGPOOL { 0, 0, 0, 1, 4000, 0, 0, 0, 0 } + /** * Initialize a pool. * @@ -49,7 +52,7 @@ typedef struct { * To allocate items of fixed size, use like this: * * git_pool_init(&pool, sizeof(item), 0); - * git_pool_malloc(&pool, 1, &my_item_ptr); + * my_item = git_pool_malloc(&pool, 1); * * Of course, you can use this in other ways, but those are the * two most common patterns. @@ -63,9 +66,14 @@ extern int git_pool_init( extern void git_pool_clear(git_pool *pool); /** + * Swap two pools with one another + */ +extern void git_pool_swap(git_pool *a, git_pool *b); + +/** * Allocate space for one or more items from a pool. */ -extern int git_pool_malloc(git_pool *pool, uint32_t items, void **ptr); +extern void *git_pool_malloc(git_pool *pool, uint32_t items); /** * Allocate space and duplicate string data into it. @@ -82,6 +90,13 @@ extern char *git_pool_strndup(git_pool *pool, const char *str, size_t n); extern char *git_pool_strdup(git_pool *pool, const char *str); /** + * Allocate space for the concatenation of two strings. + * + * This is allowed only for pools with item_size == sizeof(char) + */ +extern char *git_pool_strcat(git_pool *pool, const char *a, const char *b); + +/** * Push a block back onto the free list for the pool. * * This is allowed only if the item_size is >= sizeof(void*). |
