|
2 | 2 | #include <emscripten/emmalloc.h> |
3 | 3 |
|
4 | 4 | template<typename T> |
5 | | -T round_to_4k(T val) { |
6 | | - return (T)(((size_t)val + 4095) & ~4095); |
| 5 | +T round_to_4k(T val){ |
| 6 | + return (T)(((size_t)val + 4095) & ~4095); |
7 | 7 | } |
8 | 8 |
|
9 | | -int main() { |
10 | | - void *ptr = malloc(32*1024*1024); |
11 | | - void *ptr2 = malloc(4*1024*1024); |
12 | | - void *ptr3 = malloc(64*1024*1024); |
13 | | - void *ptr4 = malloc(16*1024); |
14 | | - void *ptr5 = malloc(2*1024*1024); |
15 | | - printf("%ld\n", (long)(ptr && ptr2 && ptr3 && ptr4 && ptr5)); |
16 | | - free(ptr2); |
17 | | - free(ptr4); |
18 | | - printf("validate_memory_regions: %d\n", emmalloc_validate_memory_regions()); |
19 | | - printf("dynamic_heap_size: %zu\n", emmalloc_dynamic_heap_size()); |
20 | | - printf("free_dynamic_memory: %zu\n", emmalloc_free_dynamic_memory()); |
21 | | - size_t numFreeMemoryRegions = 0; |
22 | | - size_t freeMemorySizeMap[32]; |
23 | | - numFreeMemoryRegions = emmalloc_compute_free_dynamic_memory_fragmentation_map(freeMemorySizeMap); |
24 | | - printf("numFreeMemoryRegions: %zu\n", numFreeMemoryRegions); |
25 | | - for (int i = 0; i < 32; ++i) { |
26 | | - printf("%zu ", freeMemorySizeMap[i]); |
27 | | - } |
28 | | - printf("\n"); |
29 | | - printf("unclaimed_heap_memory: %zu\n", round_to_4k(emmalloc_unclaimed_heap_memory())); |
30 | | - return 0; |
| 9 | +int main() |
| 10 | +{ |
| 11 | + void *ptr = malloc(32*1024*1024); |
| 12 | + void *ptr2 = malloc(4*1024*1024); |
| 13 | + void *ptr3 = malloc(64*1024*1024); |
| 14 | + void *ptr4 = malloc(16*1024); |
| 15 | + void *ptr5 = malloc(2*1024*1024); |
| 16 | + printf("valid allocs: %d\n", (int)(ptr && ptr2 && ptr3 && ptr4 && ptr5)); |
| 17 | + free(ptr2); |
| 18 | + free(ptr4); |
| 19 | + printf("emmalloc_validate_memory_regions: %d\n", emmalloc_validate_memory_regions()); |
| 20 | + printf("emmalloc_dynamic_heap_size : %zu\n", emmalloc_dynamic_heap_size()); |
| 21 | + printf("emmalloc_free_dynamic_memory : %zu\n", emmalloc_free_dynamic_memory()); |
| 22 | + size_t numFreeMemoryRegions = 0; |
| 23 | + size_t freeMemorySizeMap[32]; |
| 24 | + numFreeMemoryRegions = emmalloc_compute_free_dynamic_memory_fragmentation_map(freeMemorySizeMap); |
| 25 | + printf("numFreeMemoryRegions: %zu\n", numFreeMemoryRegions); |
| 26 | + for(int i = 0; i < 32; ++i) |
| 27 | + printf("%zu ", freeMemorySizeMap[i]); |
| 28 | + printf("\n"); |
| 29 | + printf("emmalloc_unclaimed_heap_memory : %zu\n", round_to_4k(emmalloc_unclaimed_heap_memory())); |
31 | 30 | } |
0 commit comments