Understanding MATLAB file access

조회 수: 3 (최근 30일)
Alessandro Masullo
Alessandro Masullo 2016년 3월 2일
댓글: Alessandro Masullo 2016년 3월 2일
Hello,
I'm working on a script where I have to read hundreds of images and do some calculations on them. I'm using a simple for loop with imread and I noticed something quite strange. The first time that I run the script, the imread function takes a time longer than the image analysis itself, but if I clear the memory and I run it again, the imread function is incredibly fast!
How is it possible that the second time is so much faster? I clear the memory before running the script and the images must be loaded again from the hard disk, so the bottleneck should be the disk read speed in both the cases. Is there any "hidden" memory that matlab uses to store files that I have already loaded? Or is it a matter of windows prefetch stuff?
It would be useful to know what is happening to speed up the code in advance.
Thank you.
  댓글 수: 1
John D'Errico
John D'Errico 2016년 3월 2일
Probably a question of Windows caching the file.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2016년 3월 2일
편집: Jan 2016년 3월 2일
Hard disks store last accessed data in a fast cache, which has a size of about 64 or 128 MB. So reading the file a 2nd time is usually much faster.
The operating system stores data temporarily in the RAM also, which depends on the available RAM. Under Windows 7 the size can be influenced in the registry:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\
Session Manager\Memory Management -> "LargeSystemCache"
You can disable the caching of the OS in the device manager also in the settings for the hard disk. But even then the caching of the hard disk is working.
  댓글 수: 1
Alessandro Masullo
Alessandro Masullo 2016년 3월 2일
Thank you, this explains everything!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by