.txt 文件大小有上限吗?

发布于 2024-07-10 23:35:54 字数 388 浏览 7 评论 0原文

作为圣诞礼物,我用 Java 编写了一个计算素数的小程序。 我的目的是让它整夜打开,计算下一个素数并将其写入 .txt 文件。 早上我会终止该程序并将 .txt 文件带给我的朋友作为圣诞节礼物。

有什么我应该担心的吗? 请记住,与您交谈的是真正的初学者 Ziggy,而不是某个聪明的错误检查 ASM 人员。

编辑更具体地说,由于我将让这个程序整夜计数素数,我是否有机会遇到某种与内存相关的错误? 比如,一堆堆压碎了一堆,或者狗和猫睡在一起?

编辑更具体地说,当文件大小为 4GB 时,我是否可以放入一行代码来停止打印行? 只是为了安全吗?

编辑:成功:整夜打开后,我得到的素数不超过 13 KB,我得到的最高值是 22947217,这就像数万个素数。 成功!

As a Christmas gift I have written a small program in Java to calculate primes. My intention was to leave it on all night, calculating the next prime and writing it to a .txt file. In the morning I would kill the program and take the .txt file to my friend for Christmas.

Is there anything I should be worried about? Bear in mind that this is true beginner Ziggy you are talking to, not some smart error checking ASM guy.

EDIT More specifically, since I will be leaving this program on all night counting primes, is there any chance at all that I will encounter some kind of memory related error? Like, stacks crushing heaps or dogs and cats sleeping together?

EDIT even more specifically, is there a line of code I could put in to stop the printing of lines when the file's size is 4GB? Just to be safe?

EDIT: success: after leaving it on all night I got no more than 13 KB of primes, The highest I got was 22947217, which is like tens of thousands of primes. Success!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

幻想少年梦 2024-07-17 23:35:54

我建议为您计算的每个素数发送一条短信。 你的朋友会比一堆纸更喜欢它。 另外他可以更频繁地更新。

I would recommend sending an SMS message for each prime you calculate. Your friend would like that much better than a bunch of paper. Plus he can be updated much more often.

围归者 2024-07-17 23:35:54

您很可能使用的算法很慢。 随着素数变得越来越大,您的程序将花费越来越长的时间来计算单个素数。 如果让它运行整夜,文本文件到早上就不会很大。 如果超过几兆,我会印象深刻。

More than likely you are using an algorithm that is slow. As the primes get larger your program will be taking longer and longer to calculate a single prime. If you let it run over night the text file is not going to be very large in the morning. I'd be impressed if it's over a couple of megs.

攒眉千度 2024-07-17 23:35:54

有很多限制,但它们都不是 .txt 文件固有的:

  • Windows 9x 记事本不会打开文件 > 64KB。
  • Windows NT/2k/etc 的记事本没有限制,但在处理多兆字节文件时往往会卡住并锁定。 您还需要记住,大多数文本编辑器都是愚蠢的,并尝试将整个文件读入 RAM。
  • 许多软件都限制为 2GB 或 4GB 文件,具体取决于它们是否使用有符号整数或无符号整数 - 正如有人已经提到的那样,FAT32 就犯了这个错误。

There's plenty of limits, though none of them are intrinsic to .txt files:

  • Windows 9x Notepad won't open a file > 64KB.
  • Windows NT/2k/etc's Notepad has no limit, but tends to choke and lock up on multi-megabyte files. You also need to remember most text editors are dumb and try to read the entire file into RAM.
  • Lots of software is limited to 2GB or 4GB files depending on whether they use signed or unsigned ints - as someone already mentioned FAT32 is guilty of this.
尸血腥色 2024-07-17 23:35:54

从技术上讲,除了文件系统对您施加的限制之外,没有任何限制。 然而,记事本对于打开大得令人发指的文件确实很烦躁。

Technically, there is no limit except that which the file system places on you. However, Notepad is really cranky about opening obscenely large files.

滿滿的愛 2024-07-17 23:35:54

您可能会考虑跟踪写入每个文件的字节数,并在一定字节数后切换到新文件。 您还可以为您的文件提供查看器,以便您的朋友可以更轻松地查看他的礼物。 :)

You might consider tracking the number of bytes you write to each file and switching to a new one after some number of bytes. You might also provide a viewer for your files so your friend can see his gift more easily. :)

你没皮卡萌 2024-07-17 23:35:54

Ziggy——

我喜欢这个:“不是一些聪明的错误检查 ASM 家伙。” 你正在描述我们所有人!

有足够的磁盘空间并写入! 如前所述,请确保用于打开文件的编辑器可以打开非常大的文件。

节日快乐,真正的初学者 Ziggy。

Ziggy--

I love this: "not some smart error checking ASM guy." You are describing all of us!

Have plenty of disk space and write away! As previously mentioned, be sure the editor used to open your file can open very large files.

Happy holidays, true beginner Ziggy.

蒗幽 2024-07-17 23:35:54

如果没记错的话,FAT32 的文件大小限制为 4gig。

If memory serves, FAT32 has a 4gig file limit size.

剑心龙吟 2024-07-17 23:35:54

仅与您在磁盘上存储文本文件的位置的大小有关。

而且,如果您不立即将其全部写入,则您的内存+虚拟内存。

Only as to the size of the place you're storing the text file on disk.

And, if you're not writing it all right away, your memory + virtual memory.

灯下孤影 2024-07-17 23:35:54

节省一些 CPU 周期并仅下载预先计算的素数列表怎么样? 还是更“重要的想法”? :)

How about saving some CPU cycles and just downloading a pre-computed list of primes? Or is it more "the thought that counts"? :)

夏の忆 2024-07-17 23:35:54

只为每个质数创建一个文件,然后使用文件名显示该数字怎么样?

What about just creating one file for each prime number and then use the filename to display the number?

秋意浓 2024-07-17 23:35:54

不知怎的,我怀疑当你的程序运行一整夜时,文件大小会成为一个问题,因为随着数字变大,找到素数将需要更长的时间。 只要确保你清理干净,否则你可能会耗尽你所有的内存。

回答你的问题:理论上,文件系统限制文件大小。 然而,许多文本编辑器在加载大文件(> 100 MB)时会崩溃(vim 不会),因为它们试图将其放入一个缓冲区中。

总而言之,请考虑将文件分成最薄弱的链接(文本编辑器)可以处理的块。

Somehow I doubt that when having your program run overnight, that the filesize will be a problem, considering that it will take longer to find primes as numbers get bigger. Just make sure you clean up or you might eat up all your RAM.

To answer your question: Theoretically, the filesystem restricts file size. However, a lot of text editors crash (vim does not) when loading big files (> 100 MB), because they try to fit it in one buffer.

To sum up, consider splitting up your files into chunks the weakest link (text editors) can handle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文