在 c++ 中搜索分隔符时读取文件块的最佳方法?
我想根据换行符的数量将一个文件分成几个新文件。目前,我只逐字节读取,在每次读取时查找换行符。我的问题是我觉得我的方法太慢了。我不想调用任何函数。关于每次读取调用应该执行多大的块,我是否应该遵循一条规则?
我在想也许我应该分块读取,然后迭代每个块寻找换行符并将光标设置在该换行符之后。不过,我不确定这如何在运行时节省我的时间。使用 read 调用逐字节读取是否会比我迭代每个块花费更长的时间?
另外,IO库之间有区别吗?我听说过 IO 流的工作原理,但不知道它比 C 的 IO 系统调用库更好。
I want to split a file into several new files depending on the number of new line characters there are. Currently, I only read byte by byte looking for the newline character at each read. My issue is that I feel that my method is too slow. I do not want to call any functions. Is there a rule that I should follow in regards to how big of a chunk at each read call I should be doing?
I was thinking that maybe I should read in chunks and then iterate over each chunk looking for the newline character and setting the cursor to just after that newline character. Though, I am not sure as to how this may save me time in terms of runtime. Is reading byte by byte using the read call gonna take longer than me iterating over each chunk?
Also, are there differences between IO libraries? I've heard of how IO streams work, but don't see how that may be better than the IO system call libraries from C.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论