Sunday, March 9, 2008

Memory management issue - FreeRTOS

FreeRTOS-A Free RTOS for ARM7, ARM9, Cortex-M3, MSP430, MicroBlaze, AVR, x86, PIC32, PIC24, dsPIC, H8S, HCS12 and 8051

Scheme 2 - heap_2.c

This scheme uses a best fit algorithm and, unlike scheme 1, allows previously allocated blocks to be freed. It does not however combine adjacent free blocks into a single large block.


-----------------------------------------------------------------------------------
Note:
上文提到, 該Memeory management無法自行結合許多小塊的Free memory fragment, 但不知道memory fragment會不會隨呼叫malloc的次數而增加?

Bug:
呼叫malloc多次 (產生多個小塊的Free memory fragment), 且每一次呼叫allocate的memory size都必須比前一次allocate的size還大, 目的是為了產生許多的memory fragment. malloc在呼叫的過程中會先尋找目前free memory fragment list中free memory size是否有符合目前需要的, 如果沒有才會在剩餘的heap空間中產生一個fragment並加到memory list中.
malloc
allocate memory失敗的原因: 在free memory fragment list中沒有符合需求的block同時剩餘的heap size也不足時便會回傳作業失敗。所以如果malloc本身有能力將free fragment list中小block重組成較大的block便可克服.


Pseudo code
u32 size;
while(++size &&
malloc(size));

No comments: