Code: Select all
;-TOP
; FreeString Helper, by mk-soft, v1.03, 18.08.2019
; *********************************************************
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_MacOS
Macro FreeGlobalString(_string_)
!XOR rsi,rsi
!LEA rdi,[v_#_string_]
!CALL _SYS_FastAllocateStringFree4
EndMacro
CompilerCase #PB_OS_Windows
Macro FreeGlobalString(_string_)
!XOR rdx,rdx
!LEA rcx,[v_#_string_]
!CALL SYS_FastAllocateStringFree4
EndMacro
CompilerCase #PB_OS_Linux
Macro FreeGlobalString(_string_)
!XOR rsi,rsi
!LEA rdi,[v_#_string_]
!CALL SYS_FastAllocateStringFree4
EndMacro
CompilerEndSelect
CompilerElse
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_MacOS
Macro FreeGlobalString(_string_)
!XOr edx,edx
!LEA ecx,[v_#_string_]
!CALL SYS_FastAllocateStringFree
EndMacro
CompilerCase #PB_OS_Windows
Macro FreeGlobalString(_string_)
!XOr edx,edx
!LEA ecx,[v_#_string_]
!CALL SYS_FastAllocateStringFree
EndMacro
CompilerCase #PB_OS_Linux
;TODO
Macro FreeGlobalString(_string_)
!XOr edx,edx
!LEA ecx,[v_#_string_]
!CALL SYS_FastAllocateStringFree
EndMacro
CompilerEndSelect
CompilerEndIf
Macro FreeStructureString(_struct_, _offset_)
ClearStructure(_struct_ + _offset_, string)
EndMacro
; *********************************************************
;
Debug "Free global string"
a.s = "Hello World!"
p.i = 0
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
!lea rax, [v_a]
!mov qword [v_p], rax
CompilerElse
!lea eax, [v_a]
!mov dword [v_p], eax
CompilerEndIf
Debug "Adress of gobale var (a) = " + p
Debug "Pointer to string = " + PeekI(p)
Debug "String from pointer = " + PeekS(PeekI(p))
Debug "----"
;a = #Null$ ; not work with PB v5.7x
FreeGlobalString(a)
Debug "Pointer to string after free global string = " + PeekI(p)
Debug "********"
Debug "Free single string inside structure"
Structure People
Name$
LastName$
City.s
Age.l
EndStructure
Student.People\Name$ = "Paul"
Student\LastName$ = "Morito"
Student\City = "New York"
Student\Age = 10
Debug "Data 1"
Debug Student\Name$
Debug Student\LastName$
Debug Student\City
Debug Student\Age
Debug "Adress to string = " + PeekI(Student+OffsetOf(People\LastName$))
Debug "String from adress = " + PeekS(PeekI(Student+OffsetOf(People\LastName$)))
;Student\LastName$ = #Null$ ; Not work with PB v5.7x
FreeStructureString(Student, OffsetOf(People\LastName$))
Debug ""
Debug "Data 2"
Debug Student\Name$
Debug Student\LastName$
Debug Student\City
Debug Student\Age
Debug "Adress to string = " + PeekI(Student+OffsetOf(People\LastName$))