我查了下MSDN,以下是相关描述:
CArchive::bNoFlushOnDelete
Prevents the archive from automatically calling Flush when the archive destructor is called. If you set this flag, you are responsible for explicitly calling Close before the destructor is called. If you do not, your data will be corrupted.这个属性设置的目的是 在对象析构之前,自己显式调用CArchive::Close()函数;但是Close()函数的作用是:
Flushes any data remaining in the buffer, closes the archive, and disconnects the archive from the file.
这里也是需要清除缓冲的。
问题是:什么情况下要设置这个属性,为什么要设置这个属性?
CArchive::bNoFlushOnDelete
Prevents the archive from automatically calling Flush when the archive destructor is called. If you set this flag, you are responsible for explicitly calling Close before the destructor is called. If you do not, your data will be corrupted.这个属性设置的目的是 在对象析构之前,自己显式调用CArchive::Close()函数;但是Close()函数的作用是:
Flushes any data remaining in the buffer, closes the archive, and disconnects the archive from the file.
这里也是需要清除缓冲的。
问题是:什么情况下要设置这个属性,为什么要设置这个属性?
既然无论如何都是要清除缓存的,那何必设置这样一个属性来区分呢?
请问为什么要设置这么一个属性呢?这两种情况有什么 除了调用Close()/Flush()位置不同外 还有什么不同?
析构函数中清楚缓存是不可控制的,不能完全确定是否完成了要求的操作,最好能通过flash或close函数清除缓存