Skip to content

Commit 873d7d1

Browse files
maciejbocianski0xc0170
authored andcommitted
malloc test - reduce heap usage
1 parent 7a5ffad commit 873d7d1

File tree

1 file changed

+7
-2
lines changed
  • TESTS/mbedmicro-rtos-mbed/malloc

1 file changed

+7
-2
lines changed

TESTS/mbedmicro-rtos-mbed/malloc/main.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,22 @@ void task_using_malloc(void)
5454

5555
int main()
5656
{
57+
// static stack for threads to reduce heap usage on devices with small RAM
58+
// and eliminate run out of heap memory problem
59+
MBED_ALIGN(8) uint8_t stack[THREAD_STACK_SIZE * NUM_THREADS];
60+
5761
Thread *thread_list[NUM_THREADS];
5862
int test_time = 15;
5963
GREENTEA_SETUP(20, "default_auto");
6064

6165
// Allocate threads for the test
6266
for (int i = 0; i < NUM_THREADS; i++) {
63-
thread_list[i] = new Thread(osPriorityNormal, THREAD_STACK_SIZE);
67+
thread_list[i] = new Thread(osPriorityNormal, THREAD_STACK_SIZE, stack + i * THREAD_STACK_SIZE);
6468
if (NULL == thread_list[i]) {
6569
allocation_failure = true;
70+
} else {
71+
thread_list[i]->start(task_using_malloc);
6672
}
67-
thread_list[i]->start(task_using_malloc);
6873
}
6974

7075
// Give the test time to run

0 commit comments

Comments
 (0)