AllocateStructure()

Syntax

*Item.StructureName = AllocateStructure(StructureName)
Description
Allocates a new dynamic structure item. This dynamic structure item is properly initialized and ready to use, without the need to call InitializeStructure(). To access the structure data, a pointer associated with the specified 'StructureName' has to be used.

Parameters

StructureName The name of the structure used to create the new dynamic item. The structure has to be already created.

Return value

The address of the new dynamic structure item, zero otherwise.

Remarks

This command is for advanced users and shouldn't be needed for most of programs. It's often a better choice to use a structured array, list or map to store dynamic structured items.

FreeStructure() can be used to free the dynamic structure item. All dynamic structures are automatically freed when the programs ends.

If the program crashes at this command, it is usually a result of a memory corruption at an earlier time in the program by writing at an area outside of the allocated memory area. Such an error can be narrowed down to the real cause using the purifier debugger tool.

Example

  Structure People
    Name$
    List Friends$()
  EndStructure
  
  *DynamicPeople.People = AllocateStructure(People)
  *DynamicPeople\Name$ = "Fred"
  AddElement(*DynamicPeople\Friends$())
  *DynamicPeople\Friends$() = "Stef"
  
  Debug *DynamicPeople\Name$
  Debug *DynamicPeople\Friends$()
  
  FreeStructure(*DynamicPeople)

See Also

FreeStructure()

Supported OS

All

<- AllocateMemory() - Memory Index - CompareMemory() ->