M
Michael D. Ober
OK, I can't figure out a way to optimize the following VB 2005 code using
StringBuilders:
Public Const RecSize as Integer = 105
Private buffer As String
Public Sub New()
init
End Sub
Public Sub New(ByVal value As String)
buffer = LSet(value, 105)
End Sub
Public Sub init()
buffer = Space(105)
End Sub
Private Function fetch(ByVal start As Integer, ByVal chars As Integer) As
String
fetch = Mid(buffer, start, chars)
End Function
Private Sub putch(ByRef s As String, ByVal start As Integer, ByVal chars As
Integer)
Mid(buffer, start, chars) = LSet(s, chars)
End Sub
Public Property BUF() as String
Get
Return fetch(1, 105)
End Get
Set(ByVal value as string)
putch(value, 1, 105)
End Set
End Property
Public Property KEY0() as String
Get
Return fetch(1, 19)
End Get
Set(ByVal value as string)
putch(value, 1, 19)
End Set
End Property
' Additional fields are also defined in the same manner.
The public interface to this class must remain as strings, but I'd like to
optimize the implementation. Note that this is a sample from our interface
to a VMS BASIC environment and this code is actually being generated by a VB
6 program from the VMS Record Management Services (RMS) definition files.
Once a data record is in this object, I need to be able to change it, but
don't want to drive the GC nuts allocating/deallocating the internal buffer
string. For each class, the total length of buffer is fixed. I can't use a
simple record because RMS allows overlapping variants and the VB 6 program
has been coded to support that.
Mike Ober.
StringBuilders:
Public Const RecSize as Integer = 105
Private buffer As String
Public Sub New()
init
End Sub
Public Sub New(ByVal value As String)
buffer = LSet(value, 105)
End Sub
Public Sub init()
buffer = Space(105)
End Sub
Private Function fetch(ByVal start As Integer, ByVal chars As Integer) As
String
fetch = Mid(buffer, start, chars)
End Function
Private Sub putch(ByRef s As String, ByVal start As Integer, ByVal chars As
Integer)
Mid(buffer, start, chars) = LSet(s, chars)
End Sub
Public Property BUF() as String
Get
Return fetch(1, 105)
End Get
Set(ByVal value as string)
putch(value, 1, 105)
End Set
End Property
Public Property KEY0() as String
Get
Return fetch(1, 19)
End Get
Set(ByVal value as string)
putch(value, 1, 19)
End Set
End Property
' Additional fields are also defined in the same manner.
The public interface to this class must remain as strings, but I'd like to
optimize the implementation. Note that this is a sample from our interface
to a VMS BASIC environment and this code is actually being generated by a VB
6 program from the VMS Record Management Services (RMS) definition files.
Once a data record is in this object, I need to be able to change it, but
don't want to drive the GC nuts allocating/deallocating the internal buffer
string. For each class, the total length of buffer is fixed. I can't use a
simple record because RMS allows overlapping variants and the VB 6 program
has been coded to support that.
Mike Ober.