Skip to content

Commit

Permalink
Support fetching the memory usage of a delta index
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Brian Downing authored and Junio C Hamano committed Jul 12, 2007
1 parent a1dab41 commit 11779e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions delta.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ create_delta_index(const void *buf, unsigned long bufsize);
*/
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
*
Expand Down
10 changes: 10 additions & 0 deletions diff-delta.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ struct index_entry {
};

struct delta_index {
unsigned long memsize;
const void *src_buf;
unsigned long src_size;
unsigned int hash_mask;
Expand Down Expand Up @@ -159,6 +160,7 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
mem = hash + hsize;
entry = mem;

index->memsize = memsize;
index->src_buf = buf;
index->src_size = bufsize;
index->hash_mask = hmask;
Expand Down Expand Up @@ -228,6 +230,14 @@ void free_delta_index(struct delta_index *index)
free(index);
}

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.
Expand Down

0 comments on commit 11779e7

Please sign in to comment.