Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(577)

Side by Side Diff: include/core/SkTypes.h

Issue 24251008: Add sk_calloc. Remove SkMemory_stdlib, which seems unused. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: use sk_out_of_memory Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gyp/tests.gyp ('k') | src/core/SkMemory_stdlib.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkTypes_DEFINED 10 #ifndef SkTypes_DEFINED
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 an exception or otherwise exit. 42 an exception or otherwise exit.
43 */ 43 */
44 SK_API extern void sk_throw(void); 44 SK_API extern void sk_throw(void);
45 45
46 enum { 46 enum {
47 SK_MALLOC_TEMP = 0x01, //!< hint to sk_malloc that the requested memory wil l be freed in the scope of the stack frame 47 SK_MALLOC_TEMP = 0x01, //!< hint to sk_malloc that the requested memory wil l be freed in the scope of the stack frame
48 SK_MALLOC_THROW = 0x02 //!< instructs sk_malloc to call sk_throw if the mem ory cannot be allocated. 48 SK_MALLOC_THROW = 0x02 //!< instructs sk_malloc to call sk_throw if the mem ory cannot be allocated.
49 }; 49 };
50 /** Return a block of memory (at least 4-byte aligned) of at least the 50 /** Return a block of memory (at least 4-byte aligned) of at least the
51 specified size. If the requested memory cannot be returned, either 51 specified size. If the requested memory cannot be returned, either
52 return null (if SK_MALLOC_TEMP bit is clear) or call sk_throw() 52 return null (if SK_MALLOC_TEMP bit is clear) or throw an exception
53 (if SK_MALLOC_TEMP bit is set). To free the memory, call sk_free(). 53 (if SK_MALLOC_TEMP bit is set). To free the memory, call sk_free().
54 */ 54 */
55 SK_API extern void* sk_malloc_flags(size_t size, unsigned flags); 55 SK_API extern void* sk_malloc_flags(size_t size, unsigned flags);
56 /** Same as sk_malloc(), but hard coded to pass SK_MALLOC_THROW as the flag 56 /** Same as sk_malloc(), but hard coded to pass SK_MALLOC_THROW as the flag
57 */ 57 */
58 SK_API extern void* sk_malloc_throw(size_t size); 58 SK_API extern void* sk_malloc_throw(size_t size);
59 /** Same as standard realloc(), but this one never returns null on failure. It w ill throw 59 /** Same as standard realloc(), but this one never returns null on failure. It w ill throw
60 an exception if it fails. 60 an exception if it fails.
61 */ 61 */
62 SK_API extern void* sk_realloc_throw(void* buffer, size_t size); 62 SK_API extern void* sk_realloc_throw(void* buffer, size_t size);
63 /** Free memory returned by sk_malloc(). It is safe to pass null. 63 /** Free memory returned by sk_malloc(). It is safe to pass null.
64 */ 64 */
65 SK_API extern void sk_free(void*); 65 SK_API extern void sk_free(void*);
66 66
67 /** Much like calloc: returns a pointer to at least size zero bytes, or NULL on failure.
68 */
69 SK_API extern void* sk_calloc(size_t size);
70
71 /** Same as sk_calloc, but throws an exception instead of returning NULL on fail ure.
72 */
73 SK_API extern void* sk_calloc_throw(size_t size);
74
67 // bzero is safer than memset, but we can't rely on it, so... sk_bzero() 75 // bzero is safer than memset, but we can't rely on it, so... sk_bzero()
68 static inline void sk_bzero(void* buffer, size_t size) { 76 static inline void sk_bzero(void* buffer, size_t size) {
69 memset(buffer, 0, size); 77 memset(buffer, 0, size);
70 } 78 }
71 79
72 /////////////////////////////////////////////////////////////////////////////// 80 ///////////////////////////////////////////////////////////////////////////////
73 81
74 #ifdef SK_OVERRIDE_GLOBAL_NEW 82 #ifdef SK_OVERRIDE_GLOBAL_NEW
75 #include <new> 83 #include <new>
76 84
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 606
599 private: 607 private:
600 void* fPtr; 608 void* fPtr;
601 size_t fSize; // can be larger than the requested size (see kReuse) 609 size_t fSize; // can be larger than the requested size (see kReuse)
602 uint32_t fStorage[(kSize + 3) >> 2]; 610 uint32_t fStorage[(kSize + 3) >> 2];
603 }; 611 };
604 612
605 #endif /* C++ */ 613 #endif /* C++ */
606 614
607 #endif 615 #endif
OLDNEW
« no previous file with comments | « gyp/tests.gyp ('k') | src/core/SkMemory_stdlib.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698