home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "basMem"
- '=====================================================================
- 'MEM.BAS by Frank Font 1995
- '
- 'This VB 4 file contains functions and definitions
- 'for constructing and manipulating a memory pool.
- '
- 'The memory pool is simulated by an array of type memrec_t. The
- 'memrec_t type is defined elsewhere.
- '
- '*********************************************************************
- 'NOTE: These program procedures are for entertainment purposes ONLY.
- '=====================================================================
- Option Explicit
-
- '---------------------------------------------------------------------
- 'Makes the specified memPool element available
- 'again for re-allocation.
- '---------------------------------------------------------------------
- Public Sub Mem_free(index As Long)
- memPool(index).status = False
- End Sub
-
- '---------------------------------------------------------------------
- 'Initializes the memPool array to empty.
- '---------------------------------------------------------------------
- Public Sub InitmemPool()
- MemPoolSize = JobsInProject * EmpsInPool + 1024
- ReDim memPool(MemPoolSize + 1)
- Dim i As Long
-
- For i = 0 To MemPoolSize
- memPool(i).status = False
- Next i
- End Sub
-
- '---------------------------------------------------------------------
- 'Returns index into the memPool array that
- 'can be used to store new data.
- '---------------------------------------------------------------------
- Public Function Mem_alloc() As Long
- Dim i As Long
- i = 0
-
- While True
- While i < MemPoolSize
- If memPool(i).status = False Then
- memPool(i).status = True
- Mem_alloc = i
- Exit Function
- End If
- i = i + 1
- Wend
- 'Need to allocate more memory to the pool.
- On Error GoTo mem_alloc_NoMemory
- MemPoolSize = MemPoolSize + 1024
- ReDim Preserve memPool(MemPoolSize)
- Dim j 'Here for speed.
- For j = i To MemPoolSize
- memPool(j).status = False
- Next j
- On Error GoTo 0
- DoEvents
- Wend
-
- mem_alloc_NoMemory:
- Beep
- MsgBox "Fatal Error - Out of internal memory pool!", 16, gProgramTitle
- End
-
- End Function
-
-