Revision history for TutDynaArrayType


Revision [22591]

Last edited on 2019-02-26 14:51:55 by fxm [Suppressed reference to fbc version 1.00.0]
Additions:
A dynamic array in a type definition is a very useful feature, but ""FreeBASIC"" did not support it before. Or rather, it did not support it directly before. However, you could create dynamic arrays by using pointers and the associated memory functions.
Deletions:
A dynamic array in a type definition is a very useful feature, but ""FreeBASIC"" doesn't support it before. Or rather, it doesn't support it directly before. However, you can create dynamic arrays by using pointers and the associated memory functions.


Revision [22578]

Edited on 2019-02-26 08:42:17 by fxm [Suppressed reference to fbc version 1.00.0]
Additions:
A dynamic array in a type definition is a very useful feature, but ""FreeBASIC"" doesn't support it before. Or rather, it doesn't support it directly before. However, you can create dynamic arrays by using pointers and the associated memory functions.
=== Dynamic arrays fields as non-static members are now supported inside UDT ===
Previous example but transposed, by using a dynamic array field as non-static member inside the UDT (feature now supported):
Deletions:
A dynamic array in a type definition is a very useful feature, but ""FreeBASIC"" doesn't support it before version 1.00.0. Or rather, it doesn't support it directly before that version. However, you can create dynamic arrays by using pointers and the associated memory functions.
=== From fbc version 1.00.0, dynamic arrays fields as non-static members are supported inside UDT ===
Previous example transposed for fbc version 1.00.0 or greater, by using a dynamic array field as non-static member inside the UDT (feature now supported):
'Define type (for fbc version >= 1.00.0):


Revision [22223]

Edited on 2018-02-11 11:24:43 by JeffMarshall [escape camel-case words]
Additions:
A dynamic array in a type definition is a very useful feature, but ""FreeBASIC"" doesn't support it before version 1.00.0. Or rather, it doesn't support it directly before that version. However, you can create dynamic arrays by using pointers and the associated memory functions.
An array is simply a contiguous block of memory that holds a certain data type. Arrays in ""FreeBASIC"" use an array descriptor to describe the data contained within the array, and you can use this same technique to build a dynamic array within a type. The two elements you need within your type-def are a pointer to a particular data type, and a size indicator.
Deletions:
A dynamic array in a type definition is a very useful feature, but FreeBasic doesn't support it before version 1.00.0. Or rather, it doesn't support it directly before that version. However, you can create dynamic arrays by using pointers and the associated memory functions.
An array is simply a contiguous block of memory that holds a certain data type. Arrays in FreeBasic use an array descriptor to describe the data contained within the array, and you can use this same technique to build a dynamic array within a type. The two elements you need within your type-def are a pointer to a particular data type, and a size indicator.


Revision [22194]

Edited on 2018-02-08 21:43:03 by sancho3 [escape camel-case words]
Additions:
'myType.darray = Reallocate(myType.darray, 10)
myType.darray = Reallocate(myType.darray, 10 * sizeof(integer)) ' Editors Note: above code line changed to this
'myType.darray = Reallocate(myType.darray, 10)
myType.darray = Reallocate(myType.darray, 10 * sizeof(integer)) ' Editors Note: above code line changed to this
//Last reviewed by ""sancho3"" on February 08, 2018 Notes: Error in code fixed and noted//
Deletions:
myType.darray = Reallocate(myType.darray, 10)
myType.darray = Reallocate(myType.darray, 10)


Revision [20685]

Edited on 2016-02-10 16:14:50 by DkLwikki [Update link format]
Additions:
//Written by [[WikiRick|rdc]]//
Deletions:
//Written by [[WikiRick rdc]]//


Revision [17282]

Edited on 2014-09-21 07:36:43 by FxMwikki [Add example transposed for fbc version >= 1.00.0 by using a dynamic array field inside UDT.]
Additions:
A dynamic array in a type definition is a very useful feature, but FreeBasic doesn't support it before version 1.00.0. Or rather, it doesn't support it directly before that version. However, you can create dynamic arrays by using pointers and the associated memory functions.
Here, you can see why the old array size was saved. In the For statement, the initialization procedure iterates through the newly added indexes, storing data within the memory segment. This is like using the Redim Preserve statement on a normal array.
This code section simply prints out the new values.
----
=== From fbc version 1.00.0, dynamic arrays fields as non-static members are supported inside UDT ===
Previous example transposed for fbc version 1.00.0 or greater, by using a dynamic array field as non-static member inside the UDT (feature now supported):
'Define type (for fbc version >= 1.00.0):
darray(Any) As Integer
Redim myType.darray(4)
For i = 0 To Ubound(myType.darray)
myType.darray(i) = i
For i = 0 To Ubound(myType.darray)
Print "darray(";i;" ):"; myType.darray(i)
'Save the current array upper bound
tmp = Ubound(myType.darray)
Redim Preserve myType.darray(10)
For i = tmp + 1 To Ubound(myType.darray)
myType.darray(i) = i
For i = 0 To Ubound(myType.darray)
Print "darray(";i;" ):";myType.darray(i)
Deletions:
A dynamic array in a type definition is a very useful feature, but FreeBasic doesn't support it. Or rather, it doesn't support it directly. However, you can create dynamic arrays by using pointers and the associated memory functions.
Here, you can see why the old array size was saved. In the For statement, the initialization procedure starts from the old index and iterates through the newly added indexes, storing data within the memory segment. This is like using the Redim Preserve statement on a normal array.
This code section simply prints out the new values.


Revision [17281]

Edited on 2014-09-20 13:30:19 by FxMwikki [Correct a logic error (but not a bug) in the example.]
Additions:
For i = tmp To myType.Size - 1
For i = tmp To myType.Size - 1
Deletions:
For i = tmp - 1 To myType.Size - 1
For i = tmp - 1 To myType.Size - 1


Revision [10419]

The oldest known version of this page was created on 2007-07-31 11:46:52 by JeffMarshall [Correct a logic error (but not a bug) in the example.]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode