フィルターのクリア

3 level nested structs leading to out of memory

1 回表示 (過去 30 日間)
Science Machine
Science Machine 2022 年 4 月 14 日
編集済み: Science Machine 2022 年 4 月 14 日
I'm initializing nested structs as:
struct('nestedLevelOne', repmat({struct('nestedLevelTwo',repmat({zeros(1,1080)}, [1,540]))} , [1,100]));
When I access and store data to these structures this is leading memory issues with 192gb ram on my workstation. Is there I am doing wrong with this?
  2 件のコメント
Akira Agata
Akira Agata 2022 年 4 月 14 日
I could generate this nested structure without any issue.
Could you tell us more detail on the process when you faced the memory issue?
By the way, I would recommend break-down your code to be read easily, like:
c1 = repmat({zeros(1,1080)}, [1,540]);
c2 = repmat({struct('nestedLevelTwo',c1)} , [1,100]);
yourStruct = struct('nestedLevelOne', c2);
Science Machine
Science Machine 2022 年 4 月 14 日
編集済み: Science Machine 2022 年 4 月 14 日
@Akira Agata when i start reading and writing to the structures with parfor loops, then this quickly leads to memory issue. So i was thinking that was due to
(1) how the structure was initialized (you just checked if the structure 'could' be initialized as such, which is not my issue),
(2) or maybe the fact i'm using nested structures (perhaps another data structure type would be better for lots of data?

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

採用された回答

Chunru
Chunru 2022 年 4 月 14 日
It takes ~472MB memory as shown below.
a = struct('nestedLevelOne', ...
repmat({struct('nestedLevelTwo',repmat({zeros(1,1080)}, [1,540]))} , [1,100]));
whos
Name Size Bytes Class Attributes a 1x100 472192864 struct
a(1)
ans = struct with fields:
nestedLevelOne: [1×540 struct]
a(1).nestedLevelOne(1)
ans = struct with fields:
nestedLevelTwo: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 … ]
size(a(1).nestedLevelOne(1).nestedLevelTwo)
ans = 1×2
1 1080
  1 件のコメント
Science Machine
Science Machine 2022 年 4 月 14 日
編集済み: Science Machine 2022 年 4 月 14 日
I see, a structure i have is 47.69 gb, so I should save that piecemeal. Also, using parfor loops would create copies of this, which would explain why 20 workers crashed it

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by