PB4.50Structures "ClearStructure can be used to clear a structured memory area. It's for advanced use only, when pointers are involved."
probably would be better this way:
"ClearStructure can be used to clear a structured memory area. It's for advanced use only, when dynamically allocated structures are involved and it's not intended to be used on a normal structured variable."
see this thread for more info:
viewtopic.php?f=13&t=41702and the relative example under
Compiler FunctionsThe ClearStructure() example should probably use ClearStructure() on a dynamically allocated structure.
something like this:
Code:
Structure People
Name$
LastName$
Age.l
EndStructure
*Student.People = AllocateMemory(SizeOf(People))
*Student\Name$ = "Paul"
*Student\LastName$ = "Morito"
*Student\Age = 10
ClearStructure(*Student, People) ; this is needed to release the strings
; Will print empty strings as the whole structure has been cleared. All other fields have been resetted to zero.
Debug *Student\Name$
Debug *Student\LastName$
Debug *Student\Age
FreeMemory(*Student) ; now is safe to release the memory
instead of the current
Code:
Structure People
Name$
LastName$
Age.l
EndStructure
Student.People\Name$ = "Paul"
Student\LastName$ = "Morito"
Student\Age = 10
ClearStructure(@Student, People)
; Will print empty strings as the whole structure has been cleared. All other fields have been resetted to zero.
;
Debug Student\Name$
Debug Student\LastName$
Debug Student\Age