Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by liamwelton · Jul 21, 2015 at 05:42 PM · standalonefile-ioasynchronouspersistentdatapath

Synchronous vs asynchronous file reading/writing

We're currently serializing and saving data for our game to a series of json files during play and also loading and deserializing at start-up/loading. The game is for PC & OSX, and we're using the PersistentDataPath as the location for these files.

We perform these actions as synchronous functions, which can cause the game to lock up during play as it executes these read/write functions. We've had a couple of bug reports around corrupted json files and, though we ensure that the save data is secure by creating a backup before writing to them, it would be good to know what the cause is.

I'm wondering if the application freeze during this synchronous read/write could possibly be the cause? I've heard that file read/writes should be performed as asynchronous tasks on certain platforms and I'm wondering if going async might eliminate this issue for us.

What have people'e experiences been with file reading/writing and synchronous functions?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Jul 22, 2015 at 12:13 PM 0
Share

You need to implement a buffer if you haven't already. Reading and writing should be a Factory-Line like process, handled almost independently and non-aggressively to the rest of the program. Dont ask for a big chunk when you need it.

Ask for little chunk, little chunk, little chunk, little chunk, now I need it, oh what do you know I already have it.

The techniques are not dissimilar to handshaking in an ASync rs232 port. The buffers are contantly flowing and you need to check if its safe to write or ready to read.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Paulius-Liekis · Jul 22, 2015 at 12:00 PM

You're more likely to have more issues with async approach, because of all the potential threading issues. And it won't solve your problem. The app blocks when synchronously reading a file, because... it's reading a file from disk :) That's what synchronous read does - it that area of the disk is not cached, then it will have to physically spin the disk and read that file, and that takes time. So the blocking time mostly depends on what's in the cache.

Anyway your problem is most likely related to these issues:

  • User kill the app during writing of the file

  • You do not close file handles properly (and data doesn't get flushed)

  • Some other bug in reading / writing

  • F-up files on user harddrive (which is not very likely, but possible)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

file saved to iOS persistent directory exists during session but is gone next session 0 Answers

Opening data file from asset folder 2 Answers

How to set persistent data path to sdcard on android 0 Answers

Empty Application.persisentDataPath on Android device causing UnauthorizedAccessException 1 Answer

Where to save games on desktop? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges