diff options
| author | Pietro Gagliardi <[email protected]> | 2015-04-07 23:40:18 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2015-04-07 23:40:18 -0400 |
| commit | 66788e6edb8a7e59f5676ca8cf928e23583cb31a (patch) | |
| tree | 6bdd493db0e67363779f745d48a872d1967d76bc /new/alloc_darwin.m | |
| parent | 49ee58ca364d055594657f11cef04f8c8440c366 (diff) | |
Implemented the memory logging.
Diffstat (limited to 'new/alloc_darwin.m')
| -rw-r--r-- | new/alloc_darwin.m | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/new/alloc_darwin.m b/new/alloc_darwin.m index 4b768b6..df29566 100644 --- a/new/alloc_darwin.m +++ b/new/alloc_darwin.m @@ -1,27 +1,34 @@ // 4 december 2014 +#import <stdio.h> #import "uipriv_darwin.h" // TODO is there a better alternative to NSCAssert()? preferably a built-in allocator that panics on out of memory for us? -void *uiAlloc(size_t size) +void *uiAlloc(size_t size, const char *type) { void *out; out = malloc(size); NSCAssert(out != NULL, @"out of memory in uiAlloc()"); memset(out, 0, size); +#ifdef uiLogAllocations + fprintf(stderr, "%p alloc %s\n", out, type); +#endif return out; } -void *uiRealloc(void *p, size_t size) +void *uiRealloc(void *p, size_t size, const char *type) { void *out; if (p == NULL) - return uiAlloc(size); + return uiAlloc(size, type); out = realloc(p, size); NSCAssert(out != NULL, @"out of memory in uiRealloc()"); // TODO zero the extra memory +#ifdef uiLogAllocations + fprintf(stderr, "%p realloc %p\n", p, out); +#endif return out; } @@ -30,4 +37,7 @@ void uiFree(void *p) if (p == NULL) return; free(p); +#ifdef uiLogAllocations + fprintf(stderr, "%p free\n", p); +#endif } |
