为什么我需要时间关闭流中的文件
Why I need times in closing files in flow
我是 c++ 的新手,我有问题。
我有这样的代码:
void FlowState::closeFile() {
if (outfile) {
//from here
struct timeval times[2];
times[0] = myflow.tstart;
times[1] = myflow.tstart;
outfile->flush();
outfile->close();
//to here
}
}
我对所选零件有疑问。为什么我需要这个?它是如何工作的?
这可能会有所帮助:
class FlowState {
public:
string flowid;
class Streamdemux &demux;
Flow myflow;
// ...
FlowState(class Streamdemux &demux_, const Flow &flow_,
u_int32_t isn_, bool tcp);
virtual ~FlowState();
// ...
};
和:
class Flow: public flowAddr {
public:
int32_t vlan;
struct timeval tstart;
struct timeval tlast;
uint64_t packet_count;
uint64_t connection_count;
string fileNameTemplate;
Flow() :
vlan(), tstart(), tlast(), packet_count(), connection_count() {
fileNameTemplate = "%S:%s-%D:%d"; //brakuje ID połączenia
}
Flow(const flowAddr &flowAddr_, uint16_t vlan_,
const struct timeval &t1, const struct timeval &t2,
uint64_t connection_count_) :
flowAddr(flowAddr_), vlan(vlan_), tstart(t1), tlast(t2), packet_count(
0), connection_count(connection_count_) {
fileNameTemplate = "%S:%s-%D:%d";
}
virtual ~Flow() {
}
};
可以这样想:你有一个运行很长时间的程序,不时打开文件。但是,与计算机上的其他所有内容一样,文件句柄是有限的资源。因此,如果程序不关闭文件,它迟早会用完可用的文件句柄。
相关文章:
- 从文本文件中读取时钟时间和事件时间并进行处理
- Levenshtein 两个文件的距离花费了太多时间
- 如何从远程 SFTP 服务器获取 HH-MM-SS 时间戳格式的文件列表
- 如何将消息时间戳写入日志文件?
- Chilkat SFTP 文件修改时间不与上传更新
- 如何在 Windows 上的 C++ 中根据文件的修改时间读取目录中的文件
- 正在等待在非阻塞文件描述符上长时间运行ioctl
- C++-需要读取存储在文件(.txt)中的时间戳并正确检索
- 测量任何 Windows 可执行文件的内存使用情况和执行时间
- std::fstream 需要很长时间才能将大数据写入.csv文件中
- 如何减少编译时间:在包含未触及的头文件的情况下
- 当字节在文件上写入0时,是否可以保持写作时间稳定
- C++ 如何使用字符串中保存的文件路径创建带时间戳的目录
- 使用LTO静态链接的可执行文件(链接时间优化):如何使用以前构建的库进行制作
- 在C++中将数据和时间分配给文件时间结构
- VC++ 中的文件时间结构
- c++ 将文件时间转换为秒
- 系统时间、本地时间、文件时间和正常时间
- 为什么我的程序终止调用KERNEL32!文件时间到系统时间 ()
- CUDA中的系统时间和文件时间