![]() This function is for advanced users and should be used with care. There is no internal check to ensures the structure Set to zero, even native type like long, integer etc. 'Structure' is the name of the structure which should be used to perform the clearing. This is useful when the structure contains strings, array, list or map which have been allocated internally by PureBasic. Syntax ClearStructure(*Pointer, Structure)ĬlearStructure clears a structured memory area. There is no internal check to ensures that the structure match the two memory area. It could crash, as random values will be used by the clear routine. Should be a valid structure memory area, or a cleared memory area. Needed to call ClearStructure before CopyStructure. The destination structure will be automatically cleared before doing the copy, it's not This is useful when dealing with dynamic allocations, through pointers. Syntax CopyStructure(*Source, *Destination, Structure)ĬopyStructure copy the memory of a structured memory area to another. Print out the list content ForEach *Student\ Friends() Now the list is ready to use AddElement(*Student\ Friends()) *Student.People = AllocateMemory( SizeOf(People)) Warning: multiple calls to InitializeStructure create a memory leakīecause the old members are not freed ( ClearStructure has to be called before calling InitializeStructure 'Structure' is the name of the structure which should be used to perform the initialization. It initializes structure members of type Array, List and Map, other members are not affected (.s. InitializeStructure initialize the specified structured memory area. Syntax InitializeStructure(*Pointer, Structure) #PB_Constant #PB_Variable #PB_Array #PB_List #PB_Map #PB_Structure #PB_Interface #PB_Procedure #PB_Function #PB_OSFunction #PB_Label #PB_Prototype #PB_Module #PB_EnumerationĬompilerIf Defined(PureConstant, #PB_Constant)ĭebug "Constant 'PureConstant' is declared" The 'Type' parameter can be one of the following values: (ie: without the '#' for a constant, without '()' for an The 'Name' parameter has to be specified without any extra decoration The specified subsystem name is not case-sensitive.ĭebug "Compiling with the OpenGL subsystem"ĭefined checks if a particular object of a code source like structure, Subsystem can be used to find out if a subsystem is in use for the If TypeOf(Surface) = #PB_Float Debug "Surface is a 'Float'" #PB_Byte #PB_Word #PB_Long #PB_String #PB_Structure #PB_Float #PB_Character #PB_Double #PB_Quad #PB_List #PB_Array #PB_Integer #PB_Map #PB_Ascii #PB_Unicode #PB_InterfaceĮndStructure If TypeOf(Person\Age) = #PB_Word Debug "Age is a 'Word'" ![]() TypeOf can be used to find out the type of a variable, Offset, so it will be IndexOfTheFunction*SizeOf(Integer).ĮndStructure Debug OffsetOf(Person\Age) will be 8 on 32-bit compiler as a string pointer is 4 bytes in memory will be 16 on 64-bit compiler as a string pointer is 8 bytes in memory Interface ITestĮndInterface Debug OffsetOf(ITest\ Destroy()) will be 4 on 32-bit compiler as a pointer is 4 bytes in memory will be 8 on 64-bit compiler as a pointer is 8 bytes in memory When used with an Interface, the function index is the memory OffsetOf can be used to find out the address offset of a Structure field or the address offset An Ascii variable (.a) is AsciiĮxample: 1 char.c= '!' Debug SizeOf(char) display 2Īscii.a= '!' Debug SizeOf(ascii) display 1ĮndStructure Debug "The size of my friend is "+ Str( Sizeof(Person))+" bytes" will be 10 on 32-bit compiler as a string pointer is 4 bytes in memory will be 18 on 64-bit compiler as a string pointer is 8 bytes in memory Note: A Character (.c) variable is unicode and uses 2 bytes. To another variable if inside a loop or often called procedure.Īs a compile time function SizeOf doesn't work with runtime Array, List or Map.ĪrraySize(), ListSize() or MapSize() can be used instead. This can be useful in many areas such as calculating memory requirements for operations,Īs a compiler function, SizeOf(x) is assigned to a constant and does not require assignment SizeOf can be used to find the size of any complex Structure, built-in type (word, float,Įtc.), Interface or even ReferenceLink "variables" "variables" (Structures with same name as variable take precedence).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |