[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] pygame and file object compatibility; slow.





On Sat, Mar 27, 2010 at 11:11 PM, Maize <vhxonline@xxxxxxxxx> wrote:
Currently I am working on a game project in pygame. We have a library
folder containing all of our images, text files, and fonts. We are
converting this to an archive file because we have many many files
(~12,000) and don't want to litter folders and files everywhere on a
users computer. We turned to the tarfile module simply because it was
built in and easy to use. Currently, I am using tarfile's extractfile
to retrieve a file object from the tar file and put it into memory.
Pygame does not like tarfile's file objects at all.

Using pygame.image.load, if I pass the filename and directory, the
load time is near instant at 0.0 ~ 0.0009s. Whereas passing the file
object created by tarfile increases the load time to an insane 1.4 -
1.5s! Even worse: passing a file object to pygame.font.Font produces a
segmentation fault. Am I missing something or is there an issue with
tar file objects?

in Python a "file" object is just an object that contains some specific methods, read, write, etc.  It's not specified how the library actually implements them.
It sounds like your files aren't being extracted until load time.  Perhaps you can pre-extract the files you need into memory before loading?  That would most likely fix your issue.

Also there is a zip library built into Python, isn't there?  Why use tar?  tar files aren't even compressed, are they?

I have a feeling this will be consistent with many different file
objects. Any help is greatly appreciated and welcomed.
Um, no, this is specific to their implementation of file objects.  That's the side-effect of duck-typing, you have to depend on libraries implementing their interfaces correctly.
Sounds like something's wrong with the tar library, or you're not using it in the intended manner.

I'd personally look into using another library and extracting to memory at runtime, unless you are running on a platform with severe memory constraints?

-Luke