append bug maybe.

조회 수: 2 (최근 30일)
hangjun ji
hangjun ji 2020년 4월 30일
댓글: hangjun ji 2020년 5월 1일
In the .mat file, append the variable with the append command, which has the same name as the original variable in the file. Although it is overwritten, the file size is the sum of the two variables, which results in the file getting larger and larger. In fact, multiple variables in the file After saving from the workspace is very small. We think this is a bug and there is no real coverage. wonder if it is or not

채택된 답변

Walter Roberson
Walter Roberson 2020년 4월 30일
편집: Walter Roberson 2020년 4월 30일
This is by design. When you -append, then the .mat file as a whole is not rewritten: instead the place in the .mat file that stored the variable is marked as unused and the new information is put at the end of the file.
If you were to later save a smaller version of the same variable, then the now-empty block in the file might be re-used, but this is not promised.
-append makes no attempt to "compact" the file to remove the hole. It was designed for the situation where small update time was more important than smallest file.
  댓글 수: 10
Walter Roberson
Walter Roberson 2020년 4월 30일
Often files such as .mat files are designed so that if something goes wrong during an update, that you do not lose the old information, or at least designed to reduce the risk of losing the old information. If you were to re-use the disk space immediately (in the case where the new version of the variable can fit into the old location) then if you stop writing for some reason (reboot, kill the process) then the .mat file would end up with the old variable version being gone and the new variable version not being all there yet. It is more reliable to write the new material at the end of the file (or at least in an empty block that is big enough and is after the original variable in the file) and then once it is in place, to invalidate the old variable that is earlier in the file. If you do this, then at any time, the valid version of the variable is the first one you can find in the file.
If you were to deliberately look for holes in the file that are large enough to fit the new version of the variable (and you would have to know its compressed size to know if it would fit) then as you write out the new version, until it is completely written out, scanning the file would find the new not-ready version first. There are ways to work with that: you could write out a version marked as not being in use yet, then afterwards go back and mark it as active, then go find the old version later in the file and remove it, But the logic is simpler to just put the new version at the end until it is done and then to go and mark the old earlier version as invalid.
hangjun ji
hangjun ji 2020년 5월 1일
thanks a lot, I got it.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by