|
11 | 11 | #include "mem_alloc.h" |
12 | 12 | #include "os_print.h" |
13 | 13 |
|
14 | | -#define SIZE_MEM_BUFFER_MAIN 10240 |
15 | | -#define SIZE_MEM_BUFFER_ALT 2048 |
16 | | -#define SIZE_MEM_BUFFER (SIZE_MEM_BUFFER_MAIN + SIZE_MEM_BUFFER_ALT) |
| 14 | +#define SIZE_MEM_BUFFER (1024 * 12) |
17 | 15 |
|
18 | 16 | static uint8_t mem_buffer[SIZE_MEM_BUFFER] __attribute__((aligned(sizeof(intmax_t)))); |
19 | | -static uint16_t mem_legacy_idx; |
20 | 17 | static mem_ctx_t mem_ctx = NULL; |
21 | 18 |
|
22 | 19 | #ifdef HAVE_MEMORY_PROFILING |
@@ -55,59 +52,3 @@ void app_mem_free_impl(void *ptr, const char *file, int line) { |
55 | 52 | #endif |
56 | 53 | mem_free(mem_ctx, ptr); |
57 | 54 | } |
58 | | - |
59 | | -/** |
60 | | - * Initializes the memory buffer index |
61 | | - */ |
62 | | -void mem_legacy_init(void) { |
63 | | - mem_legacy_idx = 0; |
64 | | - // initialize the new allocator to still be able to use it, just in case |
65 | | - mem_ctx = mem_init(mem_buffer + SIZE_MEM_BUFFER_MAIN, SIZE_MEM_BUFFER_ALT); |
66 | | -} |
67 | | - |
68 | | -/** |
69 | | - * Resets the memory buffer index |
70 | | - */ |
71 | | -void mem_legacy_reset(void) { |
72 | | - mem_legacy_init(); |
73 | | -} |
74 | | - |
75 | | -/** |
76 | | - * Allocates (push) a chunk of the memory buffer of a given size. |
77 | | - * |
78 | | - * Checks to see if there are enough space left in the memory buffer, returns |
79 | | - * the current location in the memory buffer and moves the index accordingly. |
80 | | - * |
81 | | - * @param[in] size Requested allocation size in bytes |
82 | | - * @return Allocated memory pointer; \ref NULL if not enough space left. |
83 | | - */ |
84 | | -void *mem_legacy_alloc(size_t size) { |
85 | | - size_t new_idx; |
86 | | - |
87 | | - if (__builtin_add_overflow((size_t) mem_legacy_idx, size, &new_idx)) { |
88 | | - PRINTF("Error: overflow detected!\n"); |
89 | | - return NULL; |
90 | | - } |
91 | | - // Buffer exceeded |
92 | | - if (new_idx > SIZE_MEM_BUFFER_MAIN) { |
93 | | - PRINTF("Error: mem_alloc(%u) failed!\n", size); |
94 | | - return NULL; |
95 | | - } |
96 | | - mem_legacy_idx += size; |
97 | | - return &mem_buffer[mem_legacy_idx - size]; |
98 | | -} |
99 | | - |
100 | | -/** |
101 | | - * De-allocates (pop) a chunk of memory buffer by a given size. |
102 | | - * |
103 | | - * @param[in] size Requested deallocation size in bytes |
104 | | - */ |
105 | | -void mem_legacy_dealloc(size_t size) { |
106 | | - // More than is already allocated |
107 | | - if (size > mem_legacy_idx) { |
108 | | - PRINTF("Warning: mem_dealloc(%u) with a value larger than allocated!\n", size); |
109 | | - mem_legacy_idx = 0; |
110 | | - } else { |
111 | | - mem_legacy_idx -= size; |
112 | | - } |
113 | | -} |
0 commit comments