Pergunta

Como um presente de Natal que eu escrevi um pequeno programa em Java para primes calcular. Minha intenção era deixá-lo ligado durante toda a noite, o cálculo do primeiro seguinte e escrevê-lo em um arquivo .txt. Na parte da manhã eu mataria o programa e levar o arquivo .txt ao meu amigo para o Natal.

Existe alguma coisa que eu deveria estar preocupado? Tenha em mente que este é verdadeiro iniciante Ziggy você está falando, verificando não algum erro inteligente cara ASM.

EDIT Mais especificamente, uma vez que estará deixando este programa em todos os primos de contagem noite, há alguma chance de que eu vou encontrar algum tipo de erro de memória relacionada? Como, pilhas esmagamento montes ou cães e gatos dormindo juntos?

EDIT ainda mais especificamente, existe uma linha de código que eu poderia colocar em parar a impressão das linhas quando o tamanho do arquivo é de 4 GB? Apenas para ser seguro?

EDIT: o sucesso: depois de deixá-lo em toda a noite Eu não tenho mais de 13 KB de primos, o mais alto que consegui foi 22.947.217, que é como dezenas de milhares de números primos. Sucesso!

Foi útil?

Solução

Mais do que provável que você está usando um algoritmo que é lento. Como os primos se tornam maiores o seu programa vai tomar mais tempo e mais tempo para calcular uma única prime. Se você deixá-lo correr noite sobre o arquivo de texto não vai ser muito grande na parte da manhã. Eu ficaria impressionado se é sobre um par de megas.

Outras dicas

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.

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.

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

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. :)

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

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.

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.

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

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

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top