diff options
author | antirez <antirez@gmail.com> | 2012-02-07 13:05:36 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2012-02-07 13:05:36 +0100 |
commit | 442246dde2d8842caf4c1f4d4694ef5a78a0bad8 (patch) | |
tree | bf4231157829a83942633b8c22f2a9d0bf431010 /src/zmalloc.c | |
parent | 8b7c3455b964d634453cfe7acdb833db10a2fed5 (diff) | |
download | redis-442246dde2d8842caf4c1f4d4694ef5a78a0bad8.tar.gz |
Precision of getClientOutputBufferMemoryUsage() greatily improved, see issue #327 for more information.
Diffstat (limited to 'src/zmalloc.c')
-rw-r--r-- | src/zmalloc.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/zmalloc.c b/src/zmalloc.c index 56b9140c9..89f80d833 100644 --- a/src/zmalloc.c +++ b/src/zmalloc.c @@ -150,6 +150,20 @@ void *zrealloc(void *ptr, size_t size) { #endif } +/* Provide zmalloc_size() for systems where this function is not provided by + * malloc itself, given that in that case we store an header with this + * information as the first bytes of every allocation. */ +#ifndef HAVE_MALLOC_SIZE +size_t zmalloc_size(void *ptr) { + void *realptr = (char*)ptr-PREFIX_SIZE; + size_t size = *((size_t*)realptr); + /* Assume at least that all the allocations are padded at sizeof(long) by + * the underlying allocator. */ + if (size&(sizeof(long)-1)) size += sizeof(long)-(size&(sizeof(long)-1)); + return size+PREFIX_SIZE; +} +#endif + void zfree(void *ptr) { #ifndef HAVE_MALLOC_SIZE void *realptr; |