path: root/Documentation/technical/api-allocation-growing.txt
diff options
authorRené Scharfe <>2014-09-16 18:56:48 (GMT)
committerJunio C Hamano <>2014-09-18 16:13:38 (GMT)
commit3ac22f82edec108986b2627fcd6f2a8039617a23 (patch)
tree91f4cd65a867a4808d731e61e63b90d2abbea29e /Documentation/technical/api-allocation-growing.txt
parentce1d3a93a6405b8a0313491df3099919ed3d150f (diff)
The macro ALLOC_GROW manages several aspects of dynamic memory allocations for arrays: It performs overprovisioning in order to avoid reallocations in future calls, updates the allocation size variable, multiplies the item size and thus allows users to simply specify the item count, performs the reallocation and updates the array pointer. Sometimes this is too much. Add the macro REALLOC_ARRAY, which only takes care of the latter three points and allows users to specfiy the number of items the array can store. It can increase and also decrease the size. Using the macro avoid duplicating the variable name and takes care of the item sizes automatically. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'Documentation/technical/api-allocation-growing.txt')
1 files changed, 3 insertions, 0 deletions
diff --git a/Documentation/technical/api-allocation-growing.txt b/Documentation/technical/api-allocation-growing.txt
index 542946b..5a59b54 100644
--- a/Documentation/technical/api-allocation-growing.txt
+++ b/Documentation/technical/api-allocation-growing.txt
@@ -34,3 +34,6 @@ item[nr++] = value you like;
You are responsible for updating the `nr` variable.
+If you need to specify the number of elements to allocate explicitly
+then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.