Memory usage of functions like pause()
5 次查看(过去 30 天)
显示 更早的评论
Hi,
I have deployed my code that controls and reads a DAQ device on a desktop computer. Actually the program is supposed to run for a long time (many days), however I need to record the data with a sampling rate of 20kHz. Therefore I analyze the signal every few seconds and store only the relevant information on the harddisc.
Unfortunately I constantly reach the memory limit of the desktop computer. Now I am looking for lines in the code where more memory is constantly used. For this I use:
profile -memory on
%% function()
profreport
I have implemented this in a version of my program. When evaluating the report I came across some lines that I do not understand. Here is a selection:
- I have a control loop running
while 1
pause(0.1)
%% Check if ...
end
this loop is called very often, however the pause() function creates 242mb/266mb/7.65mb memory for it. Do I understand correctly that the function allocates 242mb and frees 266mb in the course? How can this be?
- During my measurement I read the data with 4Hz from the hardware buffer and write it to a .bin file. As soon as a data set is complete, after 100s, I read it out and analyze the signal. Thereby I load a dataset data(2000000,6) with values type single. After the analysis the variable out(80,2*n) remain, with n is the number of analysis cycles done. I then clear the large data variable and the .bin file and rewrite again. So in the peak I would expect the final size of (2000000,6). However, it says here:
% s calls mem line
4.509 108 2.6g/15.6m/39.3m 82 fileID = fopen(par.tempfile);
The line was called here every 100s. In this case 108 times. But 2.6g were allocated. This seems to be too much. How is this possible?
Many greetings
Max
0 个评论
回答(2 个)
Manas Meena
2021-1-7
If you are reading the data into a CHAR then double memory is required as MATLAB uses 2 byte-chars. Also passing around variables often lead to memory duplication. These can be some probable causes but it depends on your code as-well, there can be some unexpected problems.
0 个评论
Bruno Luong
2021-1-7
Pause by itself would not causes any issue. But as side effect it releases other parallel pending tasks and those might have memory leak thet you observe.
It depends what you do behind the scene, it could be memory leak from MATLAB or the third party driver, or between the interfaces of sofwares, etc...
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!