OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkVarAlloc.h" | 8 #include "SkVarAlloc.h" |
9 | 9 |
10 // We use non-standard malloc diagnostic methods to make sure our allocations ar
e sized well. | |
11 #if defined(SK_BUILD_FOR_MAC) | |
12 #include <malloc/malloc.h> | |
13 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN32) | |
14 #include <malloc.h> | |
15 #endif | |
16 | |
17 struct SkVarAlloc::Block { | 10 struct SkVarAlloc::Block { |
18 Block* prev; | 11 Block* prev; |
19 char* data() { return (char*)(this + 1); } | 12 char* data() { return (char*)(this + 1); } |
20 | 13 |
21 static Block* Alloc(Block* prev, size_t size) { | 14 static Block* Alloc(Block* prev, size_t size) { |
22 SkASSERT(size >= sizeof(Block)); | 15 SkASSERT(size >= sizeof(Block)); |
23 Block* b = (Block*)sk_malloc_throw(size); | 16 Block* b = (Block*)sk_malloc_throw(size); |
24 b->prev = prev; | 17 b->prev = prev; |
25 return b; | 18 return b; |
26 } | 19 } |
(...skipping 26 matching lines...) Expand all Loading... |
53 SkASSERT(SkIsAlignPtr(bytes)); | 46 SkASSERT(SkIsAlignPtr(bytes)); |
54 | 47 |
55 size_t alloc = 1<<fLgSize++; | 48 size_t alloc = 1<<fLgSize++; |
56 while (alloc < bytes + sizeof(Block)) { | 49 while (alloc < bytes + sizeof(Block)) { |
57 alloc *= 2; | 50 alloc *= 2; |
58 } | 51 } |
59 fBytesAllocated += alloc; | 52 fBytesAllocated += alloc; |
60 fBlock = Block::Alloc(fBlock, alloc); | 53 fBlock = Block::Alloc(fBlock, alloc); |
61 fByte = fBlock->data(); | 54 fByte = fBlock->data(); |
62 fRemaining = alloc - sizeof(Block); | 55 fRemaining = alloc - sizeof(Block); |
63 | |
64 #if defined(SK_BUILD_FOR_MAC) | |
65 SkASSERT(alloc == malloc_good_size(alloc)); | |
66 #elif defined(SK_BUILD_FOR_UNIX) && !defined(__UCLIBC__) | |
67 // TODO(mtklein): tune so we can assert something like this | |
68 //SkASSERT(alloc == malloc_usable_size(fBlock)); | |
69 #endif | |
70 } | 56 } |
OLD | NEW |