Hi folks,
in my project during runtime I download jpg-files from the web and I have to store/cache those textures for later use.
I worked out two methods. First method: I download the files an store it into the persistent data path. Later I’m able to grab the jpgs right from there using www (file://).
Second method: I download the jpgs and do a base64String-Conversion. I’m then able to store those converted picture as a string inside playerPrefs. Later I’m grab the string from the playerPrefs again, convert it back into byte and load it into the texture.
So the basic question: storing the jpgs as strings in playerPrefs or “as it is” in the persistent data path?
Which methode is better regarding memory or performance (the project should run on Mac/PC as well as on tablets/smartphones).
Thanks in advance!
I’d say it depends on the size of the images and the platform limitations you’re under… Storing them as encoded strings in playerprefs is definitely not going to be faster than storing them as files, and it won’t do much for saving up in file sizes either… In fact, IIRC, the playerprefs database was limited to 1MB storage total, IDK if that has changed though, that was the case a couple years ago.
I’d use normal files, unless you can’t do that for some reason (platform restrictions?).
Cheers
1 Like
Thank you. Yes, I came (with your help) to the conclusion to store it as files into the persistent data path. Could be possible that the pics are >1MB from time to time and you’re right, there is a Limit under some circumstances (Windows - Registry - per playerprefs-key). It’s a bit more work to manage the files in the data path but thats okay. I’ve found a way to encode the jpgs with a simple XOR-operation so if a user finds the persistent data path, he will not able to use/copy the pictures (it may be material with copyright restrictions, because of that a “caching” on a device is a bit complicated).
It’s not planned for the first release but it’s quite possible that the program will be released for iPad/Android as well. I suppose, on this devices it’s better too, to use the persistent data path? Because of memory issues (I suppose, that whole “storing-pics-into-strings-and-write-or-get-it-to-from-the-playerprefs”-story could be a memory-killer)?
Cheers