traumatic wrote:To get this straight: I didn't mean to accuse use of anything, it was merely
meant to be an advice. Sorry if you were getting this wrong.
I did understand it right! It was 100% OK how you wrote it!
traumatic wrote:And about the "thinking-thingy": I don't know, I usually avoid to think.
Macro PAUSE(msg)
MessageRequester("Info",msg)
EndMacro
Macro SYS_FreeStructure(PointerToStructure,StructName)
!PUSH dword s_#StructName
!PUSH [PointerToStructure]
!CALL _SYS_FreeStructureStrings@8
EndMacro
Structure Struct2
p.l
s1.s
s2.s
EndStructure
Structure StructAll
p.l
s1.s
st.Struct2
s2.s
EndStructure
; Without this Structure the offset data table
; "s_structall" is not created by the compiler!
Procedure Dummy_Proc()
Protected x.StructAll
EndProcedure
#TestSize = 1024*1024
PAUSE("Start");===========================================> ~ 2.2 MByte
Dim pa.l(#TestSize)
PAUSE("Array is DIM'ed!");================================> ~ 2.3 MByte
For i = 0 To #TestSize
pa(i) = AllocateMemory(SizeOf(StructAll))
Next i
PAUSE("Memory is allocated!");============================> ~ 39.2 MByte
*p.StructAll
For i = 0 To #TestSize
*p = pa(i)
With *p
\s1=Space(32)
\s2=Space(32)
\st\s1=Space(32)
\st\s1=Space(32)
EndWith
Next i
PAUSE("Strings are assigned to structure elements!");=====> ~ 187 MByte
For i = 0 To #TestSize
*p = pa(i)
SYS_FreeStructure(p_p,structall) ; name of structure in LOWECASE !!!
Next i
PAUSE("strings are free again!");========================> ~ 39.6 MByte
For i = 0 To #TestSize
*p = pa(i)
FreeMemory(*p)
Next i
PAUSE("Memory is free again!");===========================> ~ 6.9 MByte
Dim pa(0)
PAUSE("Array is cleared");================================> ~ 2.8 MByte
The first tests work!
Disadvantages:
I have to crate a dummy procedure, where all the the structures are used. Otherwise the PBCompiler does not create the "offset data table" for the structures.
The name of the structure must be given in lower case!
pointer to the structure must be given like this:
==> *PointerVariable.StructName => p_PointerVariable
==> PointerInLongVariable.l => v_PointerInLongVariable
... for now I can live with this! Nevertheless a PB-Function like this would be very nice:
Fred wrote:Actually it could be a good idea for dynamic structures, i put it on the now famous TODO list.
I would like to request similar commands to copy (copies the contents of the strings, not the pointers), compare (compares the contents of the strings, not the pointers) and clear (if strings uninitialised creates a pointer to a null, if initialised resets them to empty strings) structured memory containing strings.
Or perhaps a native PB command that gives us access to the s_ data (along with documentation on its format) so that we can write our own routines?