Memory allocation for a file
이전 댓글 표시
Hi All,
Is there a way that I can pre-allocate memory for a file? If vector elements are being assigned values in a for loop, for example, we pre-allocate memory by create the vector containing zeros. Is there some thing similar that can be done for a file being written into inside a for loop?
I open the file using fopen. Then I initiate a for loop to write data into it using fwrite and then close the file using fclose. So, I was wondering if it is possible to pre-allocate a chunk of memory for the file in an attempt to speed things up.
Thanks.
- RN
답변 (1개)
Walter Roberson
2011년 2월 25일
1 개 추천
Yes. Use fseek() to seek forward to the position of the last byte you want, and write a byte there, and then fseek() back to the beginning.
카테고리
도움말 센터 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!