求boost序列化库对于磁盘空间不足的处理方案
使用boost序列化库实现数据对象的存储,如果在未完全写入的时候由于磁盘空间不足而导致出现异常,而此时的文件已经写入一部分,即造成了文件的不完整。请问有没有什么解决方案来处理这个问题? boost序列化?磁盘空间不足
[解决办法]
这恐怕不是boost库能解决的。
建议你是序列化到内存,然后由内存一起写文件。
[解决办法]
原子操作:按整个对象序列化,而不是对象的字段逐个序列化。 要么全完成,要么删除部分写入的内容。
[解决办法]
lpNumberOfFreeClusters
Pointer to a variable for the total number of free clusters on the disk that are available to the user associated with the calling thread.
Windows NT 5.0 and later: If per-user disk quotas are in use, this value may be less than the total number of free clusters on the disk.
lpTotalNumberOfClusters
Pointer to a variable for the total number of clusters on the disk that are available to the user associated with the calling thread.
Windows NT 5.0 and later: If per-user disk quotas are in use, this value may be less than the total number of clusters on the disk.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The GetDiskFreeSpaceEx function lets you avoid the arithmetic required by the GetDiskFreeSpace function.
Windows 95:
The GetDiskFreeSpace function returns incorrect values for volumes that are larger than 2 gigabytes. The function caps the values stored into *lpNumberOfFreeClusters and *lpTotalNumberOfClusters so as to never report volume sizes that are greater than 2 gigabytes.
Even on volumes that are smaller than 2 gigabytes, the values stored into *lpSectorsPerCluster, *lpNumberOfFreeClusters, and *lpTotalNumberOfClusters values may be incorrect. That is because the operating system manipulates the values so that computations with them yield the correct volume size.
Windows 95 OSR2 and later:
The GetDiskFreeSpaceEx function is available on Windows 95 systems beginning with OEM Service Release 2 (OSR2). The GetDiskFreeSpaceEx function returns correct values for all volumes, including those that are greater than 2 gigabytes.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.
See Also
File I/O Overview, File Functions, GetDiskFreeSpaceEx, GetDriveType
[解决办法]
写入前先备份文件,成功则删除备份,失败则恢复备份,这才是成功之道!
以冗余保证数据安全,是赵老师一直以来苦口婆心的教导!
少年啊,要时刻以牢记赵老师的话而感到自豪!
[解决办法]
先写log,后写库,数据库都是这么干的
[解决办法]
写到内存先,然后判断大小,看disk空间还够。