Page 2 of 2

Re: FreeStructureStrings as normal PB FUNCTION/COMMAND

Posted: Wed Mar 22, 2006 12:40 pm
by helpy
traumatic wrote:...und wenn Du Deine Frage in Englisch stellen würdest, gäb's vielleicht auch
eine größere Chance auf eine Antwort...
Ja! Ich weiß ... man denkt einfach schneller in der Muttersprache.

Yes! I know ... it is faster to think in my native language. I posted in german by accident.

I have transleted it ... cu, helpy

Re: FreeStructureStrings as normal PB FUNCTION/COMMAND

Posted: Wed Mar 22, 2006 12:43 pm
by traumatic
helpy wrote:Ja! Ich weiß ... man denkt einfach schneller in der Muttersprache.

Yes! I know ... it is faster to think in my native language. I posted in german by accident.
To get this straight: I didn't mean to accuse you of anything, it was merely
meant to be an advice. Sorry if you were getting this wrong.

And about the "thinking-thingy": I don't know, I usually avoid to think. :D

Re: FreeStructureStrings as normal PB FUNCTION/COMMAND

Posted: Wed Mar 22, 2006 12:48 pm
by helpy
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. :D
:D

Posted: Wed Mar 22, 2006 1:41 pm
by Dare2
:lol:

Posted: Wed Mar 22, 2006 4:37 pm
by helpy
Hi all,

A workaround with a Macro:

Code: Select all

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:

Code: Select all

FreeStructureStrings(*PointerToStructure)
The Compiler should know the structure name of *PointerToStructure!

cu, helpy

Posted: Tue Aug 01, 2006 4:30 pm
by MrMat
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? :)