' ' pb_mem.bas ' ' DESCRIPTION ' Power Basic memory allocation routines. ' By Don Dickinson ' ddickinson@usinternet.com ' Sept, 2000 ' ' AUTHOR ' Don Dickinson ' ddickinson@usinternet.com ' www.basicguru.com/dickinson ' ' LICENSE and DISCLAIMER ' Hereby Public Domain ' Use this code as you see fit. By using or compiling this code or derivative ' thereof, you are consenting to the hold the author, Don Dickinson, harmless ' for all effects or side-effects its use. This code works great for me, ' but you are using it at your own risk. ' ' DEPENDS ON ' no other modules. some win32api.inc functions are conditionally ' compiled here if they're not already defined. ' ' FUNCTIONS ' Function GetMem(ByVal howMuchMemory as Long) as Long ' Sub FreeMem(ByVal memoryHandle as Long) ' #If Not %def(%PB_MEM_BAS) %PB_MEM_BAS = 1 '- I assume that if %GMEM_FIXED isn't defined, then ' none of the windows api is included (win32api.inc) ' so I declare everything that's needed by this module. ' #if not %def(%GMEM_FIXED) %GMEM_FIXED = &H0 %GMEM_MOVEABLE = &H2 %GMEM_NOCOMPACT = &H10 %GMEM_NODISCARD = &H20 %GMEM_ZEROINIT = &H40 %GMEM_MODIFY = &H80 %GMEM_DISCARDABLE = &H100 %GMEM_NOT_BANKED = &H1000 %GMEM_SHARE = &H2000 %GMEM_DDESHARE = &H2000 %GMEM_NOTIFY = &H4000 %GMEM_LOWER = %GMEM_NOT_BANKED %GMEM_VALID_FLAGS = &H7F72 %GMEM_INVALID_HANDLE = &H8000 Declare Function GlobalAlloc Lib "KERNEL32.DLL" Alias "GlobalAlloc" _ ( ByVal wFlags As Long, ByVal dwBytes As Long) As Long Declare Function GlobalFree Lib "KERNEL32.DLL" Alias "GlobalFree" _ ( ByVal hMem As Long) As Long #endif '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' GetMem '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function GetMem Alias "GetMem" (ByVal iBytes As Long) As Long Function = GlobalAlloc(%GMEM_FIXED or %GMEM_ZEROINIT, iBytes) End Function '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' FreeMem '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sub FreeMem Alias "FreeMem" (ByVal ptrMem As Long) If ptrMem Then GlobalFree ptrMem End If End Sub #endif