I am uncertain if this "trick" is now considered valid:
Based on Lothar's work:
and
I have been using this for a couple of years with success, but I am considering adapting a linked list to run within memory assigned in chunks
this way.
It's been good for a couple of years and a version (or two?) of PB but I am wondering if future versions of the PB compiler might break it because it is a "trick"?
notwithstanding
and
When used like inthe String builder example StringBuilder_New(), Lothar uses
To allocate the UDT memory. I assume this means the scope of the STRING is beyond PB recource management and remains available globally until deallocated or the process terminates?
Based on Lothar's work:
and
Code:
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ FUNCTION GetMem( BYVAL memSize AS LONG ) AS LONG ' a very smart way to allocate memory ... LOCAL MemHandle AS LONG LOCAL MemString AS STRING PTR MemString = VARPTR(MemHandle) ' String Pointer points to a NULL pointer to the data (allowed for OLE strings) @MemString = STRING$(MemSize, CHR$(0)) ' Allocate Memory ... MemHandle now points to the Memory data FUNCTION = MemHandle ' MemHandle = handle to Memory, pointer to the data END FUNCTION '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ SUB ReleaseMem( BYVAL MemHandle AS LONG ) LOCAL MemString AS STRING PTR MemString = VARPTR(MemHandle) ' let MemString be a pointer to the string which handle is MemHandle @MemString = "" ' release the Memory ... -> MemHandle = 0 END SUB
this way.
It's been good for a couple of years and a version (or two?) of PB but I am wondering if future versions of the PB compiler might break it because it is a "trick"?
notwithstanding
and
When used like inthe String builder example StringBuilder_New(), Lothar uses
Code:
psb = VirtualAlloc(BYVAL %NULL, SIZEOF(@psb), %MEM_RESERVE OR %MEM_COMMIT, %PAGE_READWRITE)
Comment