專題介紹 - 10點關於 VI memory Management的建議

原本只是我貼在LabVIEW Pro的一個解答,不過我感覺很多人需要這個技巧,所以簡單複製貼上到這邊,
這大概是寫過最簡單的專題了...

10點關於 VI memory Management的建議:


  1. 將最高維度拆開,把5D降成4D,並且將拆開後的4D資料透過FGV、DVR等功能分開儲存,避免一次操作整包資料。
  2. 如果精度沒那麼要求,可以嘗試著轉換資料型態,DBL->SGL可以省一半的memory。
    http://labviewnote.blogspot.tw/2014/05/how-to_9630.html
  3. 計算過程,減少coercion dot的使用,避免資料轉換產生的額外記憶體占用。
    http://zone.ni.com/reference/en-XX/help/371361K-01/lvconcepts/coercion_dots/
  4. 避免resize array,如build array,取而代之的改用initialize array + replace array,預先配置記憶體後以取代的方式操作element,減少記憶體重新配置造成效率低下。同時透過 In Place Element Structure來變更array element,提高程式效率及減少記憶體使用。
    http://zone.ni.com/reference/en-XX/help/371361N-01/glang/in_place_element_structure/
  5. 設法了解那些計算會導致memory buffer的產生,透過 Show Buffer Allocation來檢查memory buffer,最後選擇恰當的array opration或是 In Place Element Structure來減少memory buffer。
    http://zone.ni.com/reference/en-XX/help/371361N-01/glang/in_place_element_structure/
  6. 減少直接Branch wire來操作資料,改用Data Value Reference,減少程式complier過程自動產生data copies。
    http://www.ni.com/white-paper/9386/en/
  7. 透過Request Deallocation Function來釋放一些subVI中不被使用的記憶體。
    http://zone.ni.com/reference/en-XX/help/371361J-01/glang/request_dealloc/
  8. 在subVI上按右鍵選擇Call Setup,在VI Call Configuration Dialog Box中選擇Reload for each call,強迫calling VI只在需要時載入該VI,且使用後,該VI的記憶體空間可以釋放給其他需求使用,達到deallocated memory的行為。
    http://zone.ni.com/reference/en-XX/help/371361H-01/lvdialog/call_configuration/
  9. 將演算法規劃成Dynamic VI,透過close VI reference來強迫LabVIEW釋放該VI所占用的記憶體。
    http://www.ni.com/tutorial/14393/en/
  10. 妥善設定 VI Reentrantcy,避免LabVIEW自動clone出VI來計算巨量資料,同時也小心LabVIEW內建的API,有些演算法是被設定為pre-allocated clone,用它來計算巨量資料就直接炸了。
    http://labviewnote.blogspot.tw/2015/06/how-to-vi-re-entrant-execution.html

**7,8,9要特別注意,deallocated memory 也代表將導致下次使用時會 reallocated memory,操作次數頻繁反而降低程式效能