Efficient use of memory
Show older comments
Hello,
If i create a cell with 1000 matrices ( size of each matrix 800*1280), clearing each matrix after using it will speed up calculations ?
Example
A=cell(1000,1);
for i=1:1000
A{i}=rand(800,1280);
end
image=A{1};
image2=A{2}; % I will use image and image2 with other functions
A{1}=[];
A{2}=[];
EDIT
The real use of the cell will be like :
A=cell(1000,1);
parfor i=1:1000
A{i}=function_that_creates_image(800,1280); % image with size 800*1280 px
end
for i=1:number_of_images % number_of_images=1000 in this case
image1=A{1};
image2=A{2};
A{1}=[];
A{2}=[];
% image1 and image 2 will be used then in the next lines
%next lines of code
end
I noticed that calculating components of A in a parfor loop is faster than calculating each component for each loop inside the for loop
Thank you in advance
2 Comments
Firstly you would be better using a 3d numeric array. Or rather, firstly, why do you want 1000 large arrays all at once? Your code only shows you using 2 of them so it's impossible to make meaningful suggestions on how efficient it is having the other 998 in memory. As for clearing the 2 you have used, you should be able to see if the memory goes down in your task manager. I don't know if the memory gets free'd instantly.
As you have shown it though there is no reason to store any more than one matrix at a time.
emar
on 8 Jun 2017
Accepted Answer
More Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!