summaryrefslogtreecommitdiff
path: root/src/pool.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-06-30 12:05:25 -0700
committerRussell Belfer <rb@github.com>2014-06-30 12:05:25 -0700
commit5fa8cda981940eaef54b55abe4fcba09b4e18e12 (patch)
tree666ed1f4a261a1323600810d1591461181a068f2 /src/pool.c
parentdcdb8500e3bd719010a1a65fffc391eef23dd4b4 (diff)
downloadlibgit2-5fa8cda981940eaef54b55abe4fcba09b4e18e12.tar.gz
Round up pool alloc sizes for alignmentrb/round-up-pool-allocations
To make sure that items returned from pool allocations are aligned on nice boundaries, this rounds up all pool allocation sizes to a multiple of 8. This adds a small amount of overhead to each item. The rounding up could be made optional with an extra parameter to the pool initialization that turned on rounding only for pools where item alignment actually matters, but I think for the extra code and complexity that would be involved, that it makes sense just to burn a little bit of extra memory and enable this all the time.
Diffstat (limited to 'src/pool.c')
-rw-r--r--src/pool.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/pool.c b/src/pool.c
index 146f118b4..a516ff9eb 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -146,7 +146,7 @@ GIT_INLINE(void) pool_remove_page(
void *git_pool_malloc(git_pool *pool, uint32_t items)
{
git_pool_page *scan = pool->open, *prev;
- uint32_t size = items * pool->item_size;
+ uint32_t size = ((items * pool->item_size) + 7) & ~7;
void *ptr = NULL;
pool->has_string_alloc = 0;