Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Thoughts on the StorageDevice class


  • Please log in to reply
3 replies to this topic

#1 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 08 April 2011 - 06:08 AM

Hi Chris,

After working with the StorageDevice class for a while now, I wanted to share some thoughts with you:
  • The class is currently defined as "public static class StorageDevice".
As a 'resource' type of class, it would be beneficial to allow the following instead:
  • Allow instantiation on the heap
  • Have StorageDevice implement the IDisposable interface
These changes would allow for a using() {...} clause on the StorageDevice class which would guarantee that the resources can get cleaned up properly when an exception occurs.

For instance, today when the call to StorageDevice.MountSD() fails (at least with 4.1.1 Beta 1), the underlying SPI resources don't appear to be fully cleaned up, leaving SPI in a state that's unusable. Calling StorageDevice.Unmount() does not help to clean things up in this case since the StorageDevice.MountSD() never actually allocated the resources.

What do you think?

Cheers,
-Fabien.

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 08 April 2011 - 06:11 AM

Hi Fabien, If StorageDevice.MountSD() fails, it should clean up after itself. If it's not doing that, we should fix that :) The StorageDevice class is designed to provide static public methods for manipulation of storage devices...but we could certainly look at making it an instantiated class instead. My first thought is that would just make things more complicated for users and require more lines of code...but I'm open to it. Is there a good corollary to how this is done in the desktop .NET Framework? Chris

#3 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 08 April 2011 - 06:39 AM

If StorageDevice.MountSD() fails, it should clean up after itself. If it's not doing that, we should fix that :)


Definitely :)

Is there a good corollary to how this is done in the desktop .NET Framework?




The examples abound: from Sql connections, to files or device handles, to sockets, to web requests, to fonts, to bitmaps... Basically, anything that's a resource or that has a 'handle' to underlying system resources benefits from the using statement.


For example: http://msdn.microsof...y/yh598w02.aspx

A quick Google search reveals many other examples.

I hope this helps make the case for using :)

#4 AlfredBr

AlfredBr

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationConnecticut, USA

Posted 08 April 2011 - 03:10 PM

I too would prefer if StorageDevice were a regular class and not a static class. IMO, static classes are great for things like "Math.Xxx()" which do not hold state or have a lifetime. Also, it would allow for more natural subclassing, if it became necessary (minor).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.