On Sep 20, 2006, at 11:12 AM, Phil M wrote:


You only need to run this test once per application run, so for an optimization technique I would write the above code like this:

Function PlatformType() As String
  Static myPlatform As String
  Dim shUname As Shell

  If (myPlatform.Len = 0) Then     // not initialized
    shUname = New Shell
    shUname.Execute "uname -p"
    If (shUname.ErrorCode <> 0) Then
      // handle error - is uname corrupt???
    Else
      myPlatform = shUname.Result
    End If
  End If

  Return myPlatform
End Function

This way you only create the Shell once per application launch... after all the platform is not going to dynamically change. =)

unless of course uname fails and you never set myPlatform

Function PlatformType() As String
  const kUnknownPlatform = "unknown"
  Static myPlatform As String
  Dim shUname As Shell

  If myPlatform = "" Then     // not initialized
    shUname = New Shell
    shUname.Execute "uname -p"
    If (shUname.ErrorCode <> 0) Then
      myplatform = kUnknownPlatform
      // handle error - is uname corrupt???
    Else
      myPlatform = shUname.Result
    End If
  End If

  Return myPlatform
End Function
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to