Home > Back-end >  What is the max value of pygame.time.get_ticks()?
What is the max value of pygame.time.get_ticks()?

Time:11-13

I'm wondering, if i use pygame.time.get_ticks(), can i get a stack overflow?

I wrote a game, and the score depends on the time the player spend with it, before dies. This way, I can get a quite large number, especially measuring it in miliseconds. What's the upper limit, pygame can handle? I know, that python is only limited by my computer's memory, but it looks ineffective, even compared to itself.

What are the alternatives, if i dont want this type of memory-leak? Or is it a problem at all?

CodePudding user response:

This is 100000% not an issue. When dealing with an int Python will never throw an OverflowError.

get_ticks returns a python int, which when initialized on a 32 bit system is a 4-byte number. So it can store 2^32 values. 2^32 milliseconds is equal to about 50 days, so you are not going to run into any issues whatsoever. Even if it did somehow run longer than that, Python automatically increases the size of integers and there is no limit. Even a simple 8 byte value (2^64) can store milliseconds totaling up to 584,554,531 years.

See also How does Python manage int and long? and the OverflowError doc.

  • Related