Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Rapido
New User
Posts: 8 Joined: Fri Aug 31, 2012 2:04 pm
Post
by Rapido » Tue Jul 23, 2013 1:55 pm
Please add
Load/SaveStructuredData function, to recursive collect all fields in one memory buffer
or/and
ExamineStructure ,
NextStructureField() .
Code: Select all
Structure CC
Array a.c(1,5)
b${5}
c.s[10]
;StructureUnion
;EndStructureUnion
EndStructure
Structure BB
;*Nextbb.BB
List a$()
Map b.CC()
EndStructure
Structure AA
a.b
b.l[4]
c$
d.BB
e.q
f.i
EndStructure
Define Test.AA
*Buff=SaveStructuredData(@Test,AA)
Define Test2.AA
LoadStructuredData(@Test2,AA,*Buff)
Shield
Addict
Posts: 1021 Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:
Post
by Shield » Tue Jul 23, 2013 2:28 pm
This would require additional information to be stored about the structure and all its fields,
therefore bloating up the program. I don't know what that fancy new "Runtime" library is doing,
maybe it contains something into that direction.
Also I am not sure if such a functionality really is that useful.
It might look cool at first but if you look closer you will see some flaws
that will come into play, such as version dependency (if something changes in a new
PB version, you can't load old serialized structures anymore).
This is also a problem in languages that natively support serialization and reflection.
User_Russian
Addict
Posts: 1520 Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia
Post
by User_Russian » Tue Jul 23, 2013 3:27 pm
Shield wrote: This would require additional information to be stored about the structure and all its fields,
therefore bloating up the program. I don't know what that fancy new "Runtime" library is doing,
maybe it contains something into that direction.
Information fields structure is stored in the program. It uses many functions, for example, InitializeStructure(), CopyStructure(), etc.
Shield
Addict
Posts: 1021 Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:
Post
by Shield » Tue Jul 23, 2013 5:32 pm
No, InitializeStructure and CopyStructure are compiler functions, which, to my understanding,
means that those aren't real functions but rather cause the compiler to generate code with
different behavior based on the arguments used.
User_Russian
Addict
Posts: 1520 Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia
Post
by User_Russian » Tue Jul 23, 2013 5:41 pm
This is not the case.
For example.
Code: Select all
Structure y
x.l
y.l
EndStructure
Structure z
x.l
y.f
List ll.y()
Array aa.y(10)
EndStructure
x.z
ClearStructure(x, z)
InitializeStructure(x, z)
See part of the assembly code.
Code: Select all
; ClearStructure(x, z)
MOV eax,dword v_x
PUSH dword s_z
PUSH dword 20
PUSH eax
CALL _SYS_ClearStructure@12
;
; InitializeStructure(x, z)
MOV eax,dword v_x
PUSH dword s_z
PUSH eax
CALL _SYS_InitDynamicStructure@8
Description of the structure.
Code: Select all
s_s:
dd 0
dd -1
s_z:
dd -5,8,8,0,7
dd -4,16,8,11,7,0
dd -1
Fred
Administrator
Posts: 18162 Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:
Post
by Fred » Tue Jul 23, 2013 10:30 pm
It only store dynamic objects info, not all structure fields.
User_Russian
Addict
Posts: 1520 Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia
Post
by User_Russian » Wed Jul 24, 2013 1:43 pm
But it function ClearStructure() somehow clears structure? Why then can not copy data from the structure in memory (for example, to write to a file or transmission over the network)?
STARGÅTE
Addict
Posts: 2227 Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:
Post
by STARGÅTE » Wed Jul 24, 2013 3:09 pm
here a old example
for x86 , to get structure from a array:
Code: Select all
Structure StructureData
StructureUnion
Position.i
Type.i
EndStructureUnion
StructureUnion
ArraySize.i
ListPosition.i
EndStructureUnion
StructureUnion
ArrayPosition.i
ListStructureSize.i
EndStructureUnion
StructureUnion
SubStructureSize.i
AData.i
*ListStructureData
EndStructureUnion
*SubStructureData
Laber.i
EndStructure
#StructureData_String = 0
#StructureData_End = -1
#StructureData_FixArary = -2
#StructureData_Sub = -3
#StructureData_Array = -4
#StructureData_List = -5
#StructureData_Map = -6
Procedure.s GetStructureData_Proc(*StructureData.StructureData, StructureSize)
Protected String$, Buffer, CurrentPosition
With *StructureData
While *StructureData And \Type <> #StructureData_End
If String$ : String$ + ", " : EndIf
Select \Type
Case #StructureData_List
Buffer = \ListPosition - CurrentPosition
If Buffer : String$ + "Data["+Str(Buffer)+"], " : EndIf
String$ + "List{"+GetStructureData_Proc(\ListStructureData, \ListStructureSize)+"}"
CurrentPosition + Buffer + 8
*StructureData + SizeOf(StructureData)-4
Case #StructureData_Map
Buffer = \ListPosition - CurrentPosition
If Buffer : String$ + "Data["+Str(Buffer)+"], " : EndIf
String$ + "Map{"+GetStructureData_Proc(\ListStructureData, \ListStructureSize)+"}"
CurrentPosition + Buffer + 4
*StructureData + SizeOf(StructureData)-4
Case #StructureData_Array
Buffer = \ListPosition - CurrentPosition
If Buffer : String$ + "Data["+Str(Buffer)+"], " : EndIf
If \AData > 1
String$ + "Array(" + Str(\AData) + "){"
String$ + GetStructureData_Proc(\Laber, \ListStructureSize)
String$ + "} "
Else
String$ + GetStructureData_Proc(\Laber, \ListStructureSize)
EndIf
CurrentPosition + Buffer +4
*StructureData + SizeOf(StructureData)
Case #StructureData_FixArary
Buffer = \ArrayPosition - CurrentPosition
If Buffer : String$ + "Data["+Str(Buffer)+"], " : EndIf
If \ArraySize > 1
String$ + "Sub(" + Str(\ArraySize) + "){"
String$ + GetStructureData_Proc(\SubStructureData, \SubStructureSize)
String$ + "} "
Else
String$ + GetStructureData_Proc(\SubStructureData, \SubStructureSize)
EndIf
CurrentPosition + Buffer + \ArraySize * \SubStructureSize
*StructureData + SizeOf(StructureData)-4
Case #StructureData_Sub
Buffer = \ListPosition - CurrentPosition
If Buffer : String$ + "Data["+Str(Buffer)+"], " : EndIf
String$ + GetStructureData_Proc(\ListStructureData, \ListStructureSize)
CurrentPosition + Buffer + \ListStructureSize
*StructureData + SizeOf(StructureData)-8
Default
Buffer = \Position - CurrentPosition
If Buffer : String$ + "Data["+Str(Buffer)+"], " : EndIf
String$ + "String"
CurrentPosition + Buffer + SizeOf(String)
*StructureData + SizeOf(Integer)
EndSelect
Wend
Buffer = StructureSize - CurrentPosition
If String$ : String$ + ", " : EndIf
If Buffer : String$ + "Data["+Str(Buffer)+"]" : EndIf
EndWith
ProcedureReturn String$
EndProcedure
Macro GetArrayStructureData(ArrayName, StructureName)
GetStructureData_Proc(PeekI(@ArrayName-16), SizeOf(StructureName))
EndMacro
;- Beispiel
Structure SubComplex
Long.l
String.s
Map Words.w()
Float.f
EndStructure
Structure Complex
Long.l
Byte.b
String.s
FixArray.c[7]
FisString.s{3}
Array ComplexArray.SubComplex(40)
Double.d
List ComplexList.SubComplex()
Complex.SubComplex
EndStructure
Dim Beispiel.Complex(1)
Debug GetArrayStructureData(Beispiel(), Complex)