Advertisement
Java_Volume1 Windows API Call/ Explanation #90687

Use REAL memory to store strings. (CopyMemory i.e RtlMoveMemory, LocalAlloc, LocalFree API)

Use your machines real memory to store large strings instead of varibles that run down your programs resources.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
'Put this code in the SAME MODULE as the API ABOVE
'if you would like to download a working example this code go here:
'http://www.theblackhand.net/mouse/RealMemory.zip
Public Function malloc(Strin As String) As Long
 Dim PointerA As Long, lSize As Long
 
 lSize = LenB(Strin) 'Length of string in bytes.
 
 'Allocate the memory needed and returns a pointer to that memory
 PointerA = LocalAlloc(LPTR, lSize + 4)
 If PointerA <> 0 Then
  'Final allocation
  CopyMemory ByVal PointerA, lSize, 4
  If lSize > 0 Then
   'copy the string to that allocated memory.
   CopyMemory ByVal PointerA + 4, ByVal StrPtr(Strin), lSize
  End If
 End If
 'return the pointer to the string stored memory
 malloc = PointerA
End Function
Public Function RetMemory(PointerA As Long) As String
 Dim lSize As Long, sThis As String
 If PointerA = 0 Then
  GetMemory = ""
 Else
  'get the size of the string stored at pointer "PointerA"
  CopyMemory lSize, ByVal PointerA, 4
  If lSize > 0 Then
   'buffer a varible
   sThis = String(lSize \ 2, 0)
   'retrive the data at the address of "PointerA"
   CopyMemory ByVal StrPtr(sThis), ByVal PointerA + 4, lSize
   'return the buffer
   RetMemory = sThis
  End If
 End If
End Function
Public Sub FreeMemory(PointerA As Long)
 'frees up the memory at the address of "PointerA"
 LocalFree PointerA
End Sub
Original Comments (3)
Recovered from Wayback Machine