File: test_emmalloc_memory_statistics.cpp

package info (click to toggle)
emscripten 2.0.12~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 108,440 kB
  • sloc: ansic: 510,324; cpp: 384,763; javascript: 84,341; python: 51,362; sh: 50,019; pascal: 4,159; makefile: 3,409; asm: 2,150; lisp: 1,869; ruby: 488; cs: 142
file content (30 lines) | stat: -rw-r--r-- 920 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <emscripten/emmalloc.h>

template<typename T>
T round_to_4k(T val){
	return (T)(((size_t)val + 4095) & ~4095);
}

int main()
{
	void *ptr = malloc(32*1024*1024);
	void *ptr2 = malloc(4*1024*1024);
	void *ptr3 = malloc(64*1024*1024);
	void *ptr4 = malloc(16*1024);
	void *ptr5 = malloc(2*1024*1024);
	printf("%d\n", (int)(ptr && ptr2 && ptr3 && ptr4 && ptr5));
	free(ptr2);
	free(ptr4);
	printf("%d\n", emmalloc_validate_memory_regions());
	printf("%zu\n", emmalloc_dynamic_heap_size());
	printf("%zu\n", emmalloc_free_dynamic_memory());
	size_t numFreeMemoryRegions = 0;
	size_t freeMemorySizeMap[32];
	numFreeMemoryRegions = emmalloc_compute_free_dynamic_memory_fragmentation_map(freeMemorySizeMap);
	printf("%zu\n", numFreeMemoryRegions);
	for(int i = 0; i < 32; ++i)
		printf("%zu ", freeMemorySizeMap[i]);
	printf("\n");
	printf("%zu\n", round_to_4k(emmalloc_unclaimed_heap_memory()));
}