OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <android/log.h> | 5 #include <android/log.h> |
6 #include <jni.h> | 6 #include <jni.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 extern "C" { | 10 extern "C" { |
(...skipping 24 matching lines...) Expand all Loading... |
35 if (g_memory) | 35 if (g_memory) |
36 free(g_memory); | 36 free(g_memory); |
37 if (memory == 0) { | 37 if (memory == 0) { |
38 g_memory = NULL; | 38 g_memory = NULL; |
39 return; | 39 return; |
40 } | 40 } |
41 g_memory = static_cast<uint32_t*>(malloc(memory)); | 41 g_memory = static_cast<uint32_t*>(malloc(memory)); |
42 if (!g_memory) { | 42 if (!g_memory) { |
43 __android_log_print(ANDROID_LOG_WARN, | 43 __android_log_print(ANDROID_LOG_WARN, |
44 "MemConsumer", | 44 "MemConsumer", |
45 "Unable to allocate %ld bytes", | 45 "Unable to allocate %lld bytes", |
46 memory); | 46 memory); |
47 } | 47 } |
48 // If memory allocation failed, try to allocate as much as possible. | 48 // If memory allocation failed, try to allocate as much as possible. |
49 while (!g_memory) { | 49 while (!g_memory) { |
50 memory /= 2; | 50 memory /= 2; |
51 g_memory = static_cast<uint32_t*>(malloc(memory)); | 51 g_memory = static_cast<uint32_t*>(malloc(memory)); |
52 } | 52 } |
53 for (int i = 0; i < memory / sizeof(uint32_t); ++i) | 53 for (int i = 0; i < memory / sizeof(uint32_t); ++i) |
54 *(g_memory + i) = get_random(); | 54 *(g_memory + i) = get_random(); |
55 } | 55 } |
OLD | NEW |