2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
6 #include "include/core/SkTypes.h"
7 #include "include/private/SkMalloc.h"
10 #include <rtl/alloc.h>
12 // Based on SkMemory_malloc.cpp :
14 static inline void sk_out_of_memory(size_t size
)
16 SAL_WARN("skia", "sk_out_of_memory (asked for " << size
<< " bytes)");
20 static inline void* throw_on_failure(size_t size
, void* p
)
22 if (size
> 0 && p
== nullptr)
24 // If we've got a nullptr here, the only reason we should have failed is running out of RAM.
25 sk_out_of_memory(size
);
30 void sk_abort_no_print()
32 SAL_WARN("skia", "sk_abort_no_print");
36 void sk_out_of_memory(void)
38 SAL_WARN("skia", "sk_out_of_memory");
42 void* sk_realloc_throw(void* addr
, size_t size
)
44 return throw_on_failure(size
, rtl_reallocateMemory(addr
, size
));
47 void sk_free(void* p
) { rtl_freeMemory(p
); }
49 void* sk_malloc_flags(size_t size
, unsigned flags
)
52 if (flags
& SK_MALLOC_ZERO_INITIALIZE
)
54 p
= rtl_allocateZeroMemory(size
);
58 p
= rtl_allocateMemory(size
);
60 if (flags
& SK_MALLOC_THROW
)
62 return throw_on_failure(size
, p
);