| OLD | NEW |
| 1 #include "SkVarAlloc.h" | 1 #include "SkVarAlloc.h" |
| 2 | 2 |
| 3 // We use non-standard malloc diagnostic methods to make sure our allocations ar
e sized well. | 3 // We use non-standard malloc diagnostic methods to make sure our allocations ar
e sized well. |
| 4 #if defined(SK_BUILD_FOR_MAC) | 4 #if defined(SK_BUILD_FOR_MAC) |
| 5 #include <malloc/malloc.h> | 5 #include <malloc/malloc.h> |
| 6 #elif defined(SK_BUILD_FOR_LINUX) | 6 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN32) |
| 7 #include <malloc.h> | 7 #include <malloc.h> |
| 8 #endif | 8 #endif |
| 9 | 9 |
| 10 enum { | 10 enum { |
| 11 kMinLgSize = 4, // The smallest block we'd ever want to allocate is 16B, | 11 kMinLgSize = 4, // The smallest block we'd ever want to allocate is 16B, |
| 12 kMaxLgSize = 16, // and we see no benefit allocating blocks larger than 64K
. | 12 kMaxLgSize = 16, // and we see no benefit allocating blocks larger than 64K
. |
| 13 }; | 13 }; |
| 14 | 14 |
| 15 struct SkVarAlloc::Block { | 15 struct SkVarAlloc::Block { |
| 16 Block* prev; | 16 Block* prev; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 fBlock = Block::Alloc(fBlock, alloc, flags); | 49 fBlock = Block::Alloc(fBlock, alloc, flags); |
| 50 fByte = fBlock->data(); | 50 fByte = fBlock->data(); |
| 51 fRemaining = alloc - sizeof(Block); | 51 fRemaining = alloc - sizeof(Block); |
| 52 | 52 |
| 53 if (fLgSize < kMaxLgSize) { | 53 if (fLgSize < kMaxLgSize) { |
| 54 fLgSize++; | 54 fLgSize++; |
| 55 } | 55 } |
| 56 | 56 |
| 57 #if defined(SK_BUILD_FOR_MAC) | 57 #if defined(SK_BUILD_FOR_MAC) |
| 58 SkASSERT(alloc == malloc_good_size(alloc)); | 58 SkASSERT(alloc == malloc_good_size(alloc)); |
| 59 #elif defined(SK_BUILD_FOR_LINUX) | 59 #elif defined(SK_BUILD_FOR_UNIX) |
| 60 SkASSERT(alloc == malloc_usable_size(fByte - sizeof(Block))); | 60 // TODO(mtklein): tune so we can assert something like this |
| 61 //SkASSERT(alloc == malloc_usable_size(fBlock)); |
| 61 #endif | 62 #endif |
| 62 } | 63 } |
| 64 |
| 65 static size_t heap_size(void* p) { |
| 66 #if defined(SK_BUILD_FOR_MAC) |
| 67 return malloc_size(p); |
| 68 #elif defined(SK_BUILD_FOR_UNIX) |
| 69 return malloc_usable_size(p); |
| 70 #elif defined(SK_BUILD_FOR_WIN32) |
| 71 return _msize(p); |
| 72 #else |
| 73 return 0; // Tough luck. |
| 74 #endif |
| 75 } |
| 76 |
| 77 size_t SkVarAlloc::approxBytesAllocated() const { |
| 78 size_t sum = 0; |
| 79 for (Block* b = fBlock; b; b = b->prev) { |
| 80 sum += heap_size(b); |
| 81 } |
| 82 return sum; |
| 83 } |
| OLD | NEW |