Thursday, March 27, 2008

邊界不對齊資料和位元組排列方式

ARM 的 Load 和 Store 指令假設位址是正在下載或者儲存的資料類型長度的數倍, 如果下載和儲存的位址與資料類型邊界不對齊,可能會產生異常的結果,例如資料異常或者下載了一個旋轉位元的值。對於良好撰寫、可移植的程式碼,應該儘量避免使用邊界不對齊的存取。

C 編譯器通常情況下假設指標是邊界對齊的。

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));