Anonymous committed 11779e7

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 <>
Acked-by: Nicolas Pitre <>
Signed-off-by: Junio C Hamano <>

  • Participants
  • Parent commits a1dab41

Comments (0)

Files changed (2)

 extern void free_delta_index(struct delta_index *index);
+ * sizeof_delta_index: returns memory usage of delta index
+ *
+ * Given pointer must be what create_delta_index() returned, or NULL.
+ */
+extern unsigned long sizeof_delta_index(struct delta_index *index);
  * create_delta: create a delta from given index for the given buffer
  * This function may be called multiple times with different buffers using
 struct delta_index {
+	unsigned long memsize;
 	const void *src_buf;
 	unsigned long src_size;
 	unsigned int hash_mask;
 	mem = hash + hsize;
 	entry = mem;
+	index->memsize = memsize;
 	index->src_buf = buf;
 	index->src_size = bufsize;
 	index->hash_mask = hmask;
+unsigned long sizeof_delta_index(struct delta_index *index)
+	if (index)
+		return index->memsize;
+	else
+		return 0;
  * The maximum size for any opcode sequence, including the initial header
  * plus Rabin window plus biggest copy.