フィルターのクリア

copy-on-write, performance, and code readability

7 ビュー (過去 30 日間)
matal
matal 2013 年 11 月 26 日
回答済み: The Matlab Spot 2013 年 11 月 26 日
I use a global, multi-level nested struct() to hold a lot of data. For example, I have:
global DATA;
DATA.US.AAPL.date = <array of dates>
DATA.US.AAPL.px = <array of prices>
Exactly why I am using a structure like this or what I am storing in it is not relevant for this question. Above is just an example.
Inside of functions that operate on this structure, I often create an "alias":
function m = doStuff(region,ticker)
global DATA;
ldata = DATA.(region).(ticker);
<work on and possibly update ldata>
DATA.(region).(ticker) = ldata;
end
It's obvious that using an alias like ldata improves readability - however this appears to come at a cost. When DATA is large, replace ldata with direct DATA.(region).(ticker) leads to material performance improvement.
Presumably, the Matlab copy-on-write semantics is somehow to blame here.
Any thoughts as to how I can get readability and performance?

回答 (2 件)

Muneef
Muneef 2013 年 11 月 26 日
so are you using struct. inside a function?
  1 件のコメント
matal
matal 2013 年 11 月 26 日
yes - is the code sample unclear somehow? let me know.

サインインしてコメントする。


The Matlab Spot
The Matlab Spot 2013 年 11 月 26 日

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by