-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
60 lines (49 loc) · 1.33 KB
/
main.c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "malloc.h"
#if CONFIG_MEMORY_POOL_DEBUG
#include "debug.h"
#endif
#include <stdio.h>
#include <stdlib.h>
static void exit_function(void)
{
printf("exit function run start\n");
#if CONFIG_MEMORY_POOL_DEBUG
memory_pool_debug_trace();
printf("malloc free count: %d\n", memory_pool_debug_malloc_free_count());
#endif
printf("exit function run end\n");
}
int main(void)
{
mymem_init(SRAMIN);
mymem_init(SRAMEX);
mymem_init(SRAMCCM);
mymem_init(SRAMEX1);
mymem_init(SRAMEX2);
uint8_t* ptr = MYMALLOC(SRAMCCM, 12);
if (ptr) {
printf("ptr malloc ok, addr: %p\n", ptr);
printf("ptr memory use info: %d%%\n", mem_perused(SRAMCCM));
} else {
printf("ptr malloc fail\n");
}
uint8_t* ptr1 = MYMALLOC(SRAMCCM, 10);
if (ptr1) {
printf("ptr1 malloc ok, addr: %p\n", ptr1);
printf("ptr1 memory use info: %d%%\n", mem_perused(SRAMCCM));
} else {
printf("ptr1 malloc fail, since memory usage: %d%%\n",
mem_perused(SRAMCCM));
}
for (uint8_t i = 0; i < 6; i++) {
uint8_t* unused_ptr = MYMALLOC(SRAMEX1, 100);
if (unused_ptr == NULL) {
printf("%d malloc fail\n", i);
}
}
uint8_t* refree_ptr = ptr;
MYFREE(ptr);
MYFREE(refree_ptr);
atexit(exit_function);
return 0;
}