The Flyweight of String Pointers
Sharing intrinsic state to conserve the fragile VB6 memory limits.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Flyweight
ARCANUM SCHOOL: Transmutation // Memory Weaving
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// VB PATTERN //
' FlyweightFactory.cls
Private m_pool As Collection
Private Sub Class_Initialize()
Set m_pool = New Collection
End Sub
Public Function GetCurse(key As String) As Object
On Error Resume Next
Dim obj As Object
Set obj = m_pool.Item(key)
If obj Is Nothing Then
Set obj = CreateObject("Arcane.Curse")
m_pool.Add obj, key
End If
Set GetCurse = obj
End Function
When an army of ActiveX objects threatens to consume your 2GB user-mode memory limit, the Flyweight pattern intercedes. It pools and shares intrinsic states, weaving a tight tapestry of shared pointers.
Runic Tags:
#flyweight
#memory
#optimization