1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

Added lzma_memlimit_count().

This commit is contained in:
Lasse Collin 2008-01-16 14:46:50 +02:00
parent 19389f2b82
commit 5b5b13c7bb
2 changed files with 29 additions and 0 deletions

View file

@ -92,6 +92,16 @@ extern size_t lzma_memlimit_get(const lzma_memlimit *mem);
extern size_t lzma_memlimit_used(const lzma_memlimit *mem);
/**
* \brief Gets the number of allocations owned by the memory limitter
*
* The count does not include the helper structures; if no memory has
* been allocated with lzma_memlimit_alloc() or all memory allocated
* has been freed or detached, this will return zero.
*/
extern size_t lzma_memlimit_count(const lzma_memlimit *mem);
/**
* \brief Allocates memory with malloc() if memory limit allows
*

View file

@ -85,6 +85,25 @@ lzma_memlimit_used(const lzma_memlimit *mem)
}
extern LZMA_API size_t
lzma_memlimit_count(const lzma_memlimit *mem)
{
// This is slow; we could have a counter in lzma_memlimit
// for fast version. I expect the primary use of this
// function to be limited to easy checking of memory leaks,
// in which this implementation is just fine.
size_t count = 0;
const lzma_memlimit_list *record = mem->list;
while (record != NULL) {
++count;
record = record->next;
}
return count;
}
extern LZMA_API void
lzma_memlimit_end(lzma_memlimit *mem, lzma_bool free_allocated)
{