Code: Select all
Structure SomeStruct
a.l
EndStructure
NewMap testMap.SomeStruct()
Code: Select all
AddMapElement(testMap(),"1")
Debug "Map size: "+Str(MapSize(testMap()))
Code: Select all
testMap("1")
Debug "Map size: "+Str(MapSize(testMap()))
Because this is an array of structures, and elements are allocated for us, we can expect that the pointer to the map element is a pointer to the structure. We can prove this:
Code: Select all
Structure SomeStruct
a.l
EndStructure
NewMap testMap.SomeStruct()
testMap("1")
*element.SomeStruct=testMap("1")
*element\a=1234
Debug "Map size: "+Str(MapSize(testMap()))
Debug PeekI(*element)
Allocating a structure just for the sake of copying it into an identical structure in the map is wasteful and pointless. There should be no reason to do this:
Code: Select all
b.SomeStruct
b\a=1234
testMap("1")=b
Debug "Map size: "+Str(MapSize(testMap()))
Notice that in my earlier example I had to assign and acquire the pointer to the element in two lines:
Code: Select all
testMap("1")
*element.SomeStruct=testMap("1")
Code: Select all
*element.SomeStruct=testMap("1")
Debug "Map size: "+Str(MapSize(testMap()))
If Not FindMapElement(testMap(),"1")
Debug "No entry for 1"
EndIf
It can be proven that the result of this assignment is the same as acquiring it by its key:
Code: Select all
testMap("1")
*element.SomeStruct=testMap("1")
Debug "Pointer to map element: "+Str(*element)
*element=testMap("1")
Debug "Pointer to map element: "+Str(*element)
Code: Select all
Structure SomeStruct
a.l
EndStructure
NewMap testMap.SomeStruct()
;/ Not actually assigned to the map
*a=testMap("key")
;/ Structure was allocated and a pointer returned
Debug *a
;/ Map size is "0"
Debug "Map size: "+Str(MapSize(testMap()))