append bug maybe.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hangjun ji
le 30 Avr 2020
Commenté : hangjun ji
le 1 Mai 2020
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
0 commentaires
Réponse acceptée
Walter Roberson
le 30 Avr 2020
Modifié(e) : Walter Roberson
le 30 Avr 2020
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 commentaires
Walter Roberson
le 30 Avr 2020
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Large Files and Big Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!