01-17-2026, 09:39 PM
(This post was last modified: 01-17-2026, 09:47 PM by Unseen Machine.)
@Petr
Hope this helps, also please feel free to mod/use the idea however you wish (Youre way better at C++ than me), my only hope is that something like this can finally allow us QB64'ers to have arrays (or at least simulate them) inside udts.
The C++ backend uses dynamic vectors, so you do not need to use _Preserve or manually handle memory resizing. When you use Var_Push, the system automatically allocates more space and moves the data on the C side without any intervention required from the QB64 side. This means you never have to destroy and reload the entire structure just to change its size or add new elements. You only need to call Var_Free once on the main root parent when you are completely finished with the data, as it is designed to recursively clean up every nested child in the tree.
You can edit any specific value in an array without destroying or rebuilding the rest of the tree. By using Var_At to get the handle of a specific index, you can use the Var_Set functions to overwrite that data point instantly while leaving the surrounding structure intact. This same logic allows for multi-dimensional arrays; you simply nest Var objects inside other Var objects. For a 2D or 3D array, you push a "row" Var into a "matrix" Var, and you can then access specific coordinates by nesting your Var_At calls. This provides total flexibility for creating jagged arrays where each dimension can have a different number of elements.
I'll knock up some more demos if you need em (but i think youll be fine!)
Unseen
Hope this helps, also please feel free to mod/use the idea however you wish (Youre way better at C++ than me), my only hope is that something like this can finally allow us QB64'ers to have arrays (or at least simulate them) inside udts.
The C++ backend uses dynamic vectors, so you do not need to use _Preserve or manually handle memory resizing. When you use Var_Push, the system automatically allocates more space and moves the data on the C side without any intervention required from the QB64 side. This means you never have to destroy and reload the entire structure just to change its size or add new elements. You only need to call Var_Free once on the main root parent when you are completely finished with the data, as it is designed to recursively clean up every nested child in the tree.
You can edit any specific value in an array without destroying or rebuilding the rest of the tree. By using Var_At to get the handle of a specific index, you can use the Var_Set functions to overwrite that data point instantly while leaving the surrounding structure intact. This same logic allows for multi-dimensional arrays; you simply nest Var objects inside other Var objects. For a 2D or 3D array, you push a "row" Var into a "matrix" Var, and you can then access specific coordinates by nesting your Var_At calls. This provides total flexibility for creating jagged arrays where each dimension can have a different number of elements.
I'll knock up some more demos if you need em (but i think youll be fine!)
Unseen

