Support fetching the memory usage of a delta index
Delta indices, at least on 64-bit platforms, tend to be larger than the actual uncompressed data. As such, keeping track of this storage is important if you want to successfully limit the memory size of your pack window. Squirrel away the total allocation size inside the delta_index struct, and add an accessor "sizeof_delta_index" to access it. Signed-off-by: Brian Downing <bdowning@lavos.net> Acked-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brian Downing committed
Jul 12, 2007 at 07:55 UTC
11779e79078c9da604753e570d02134c8d4bae6a
2 files changed
+17
delta.h
+7
@@ -23,6 +23,13 @@ create_delta_index(const void *buf, unsigned long bufsize);
23
*/
24
extern void free_delta_index(struct delta_index *index);
25
26
+/*
27
+ * sizeof_delta_index: returns memory usage of delta index
28
+ *
29
+ * Given pointer must be what create_delta_index() returned, or NULL.
30
+ */
31
+extern unsigned long sizeof_delta_index(struct delta_index *index);
32
+
33
/*
34
* create_delta: create a delta from given index for the given buffer
35
*
diff-delta.c
+10
@@ -119,6 +119,7 @@ struct index_entry {
119
};
120
121
struct delta_index {
122
+ unsigned long memsize;
123
const void *src_buf;
124
unsigned long src_size;
125
unsigned int hash_mask;
@@ -159,6 +160,7 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
160
mem = hash + hsize;
161
entry = mem;
162
163
+ index->memsize = memsize;
164
index->src_buf = buf;
165
index->src_size = bufsize;
166
index->hash_mask = hmask;
@@ -228,6 +230,14 @@ void free_delta_index(struct delta_index *index)
230
free(index);
231
}
232
233
+unsigned long sizeof_delta_index(struct delta_index *index)
234
+{
235
+ if (index)
236
+ return index->memsize;
237
+ else
238
+ return 0;
239
+}
240
+
241
/*
242
* The maximum size for any opcode sequence, including the initial header
243
* plus Rabin window plus biggest copy.