Storage in XNA Game Studio 4.0


With the recently released beta of XNA Game Studio 4.0, one of the new changes you may have seen is the updates to the Storage namespace of the framework for Windows and Xbox 360. While it’s all still StorageDevice and StorageContainer, you will see that how you use these classes has changed a little bit.

The first change is in showing the selector. You used to use the Guide.BeginShowStorageDeviceSelector and Guide.EndShowStorageDeviceSelector methods for this. In XNA Game Studio 4.0, these methods have been replaced with the (much cleaner) StorageDevice.BeginShowSelector and StorageDevice.EndShowSelector. This puts them much closer to the actual type that they go with and makes them at least a little shorter to type.

The next change is in opening a StorageContainer. What used to be a call to StorageDevice.OpenContainer now is an asynchronous pattern with StorageDevice.BeginOpenContainer and StorageDevice.EndOpenContainer. This process has become asynchronous because some users have seen opening a container take multiple seconds or even minutes depending on various factors.

Additionally, making this asynchronous drives developers to perform their file operations on a different thread, which helps avoid frame hitches when saving or loading files. Because the BeginOpenContainer callback is invoked on a separate worker thread, you can perform your file operation in the callback and immediately see the gains of keeping your file operations off the main thread.

Lastly we’ve changed the interaction with StorageContainer. In previous versions you would use the StorageContainer.Path property along with normal System.IO to perform your file operations. In XNA Game Studio 4.0, we’ve moved in a direction more aligned with the IsolatedStorage APIs where StorageContainer now exposes many file operations as methods such as CreateFile, GetDirectories, and FileExists. This still gives your game the ability to perform the necessary file operations to handle saving and loading games, but also makes it easier to move from our storage APIs to IsolatedStorage when bringing your game to Windows Phone (or the opposite, of course).

Nothing huge here, but hopefully some of these changes will make your life as an XNA Game Studio user just a little bit easier whether it’s the asynchronous file operations or the easy transition between StorageContainer and IsolatedStorage.


Comments (4)

  1. Ultrahead says:

    Were those changes released within the beta? I cannot find the reference to the Storage API for the WinPhone platform 🙁

  2. Ultrahead says:

    I know I can use IsolatedStorage, I'm just wondering if StorageContainer/Device is available for WP7 on the beta.

  3. HaikuJock says:

    It's a fair point about frame hitches for synchronous file access and I've seen reports of freezing for a number of minutes on older (presumably badly fragmented) hard drives but I've never known asynchronous operations to be easier than synchronous.

  4. Tom says:

    Someone needs to make a simple storage example. All I can find is the RPG game, way to much code to sort through.

Skip to main content