Why doesn't Xojo support Arrays of Arrays Directly?

I keep running into the case where I coudl use Arrays of arrays… In the ancient past I did you a basic like language that allowed it.

Now we have to go through variants or create out own objects … but both involve object creation which is relatively expensive…

Why can’t we do something like this for all the basic types:
Dim ArrayOfStrArray() as String()

Yes that would mean
Dim StrArr() as String

would be equivalent to
Dim StrArr as String()

But so what? That latter is how we define functions… and I think that syntax would work for multidimentions.

Under the hood we could have the speed of pointer addressing but still be type safe and unambiguous at the Xojo code level.

  • Karen

you can have

  • multidimensional arrays
  • array of variant containing array
  • put array in class and use array of that class

I prefer the classes often to give more logic to the code.

[quote=141308:@Christian Schmitz]you can have

  • multidimensional arrays
  • array of variant containing array
  • put array in class and use array of that class
    [/quote]

I am aware of all of that… But often times creating a new class is overkill and often a specific class should be a friend class…

For simplicity of information hiding (as well as speed of execution) it would be easier just to be able to define such a property on relevant classes.

[quote=141310:@Karen Atkocius]I am aware of all of that… But often times creating a new class is overkill and often a specific class should be a friend class…

For simplicity of information hiding (as well as speed of execution) it would be easier just to be able to define such a property on relevant classes.[/quote]
You could make a class (like Christian suggested) called MyArrayHolder for example. You could then simply make a property for each type that this array can hold. You could then create an array of MyArrayHolders and use that.

I know Christian already suggested this but I am just explaining it. This would be a better approach than multidemensional arrays for simplicity’s sake. For performance and probably easier debugging you should (mostly) avoid variants.

And yes it would be easier if you could do this directly but by the looks of things this is the way to go.

Hope this helps

[quote=141356:@Oliver Scott-Brown]You could make a class (like Christian suggested) called MyArrayHolder for example. You could then simply make a property for each type that this array can hold. You could then create an array of MyArrayHolders and use that.
[/quote]

As I said I know how to work around it… and i fact have been doing it for over a decade.

My point was that creating objects for something like that is unnecessarily expensive. Ideally I would like to see language and framework features that help with speed and was looking to see if there was any enthusiasm for this idea.

  • Karen

Speed & memory efficiency would suggest you should use something like a sparse array which you can create using a dictionary
That way most lookups are not linear searches but O(1) operations based on a hashed key

A sparse array assumes that all the array elements do not need to be populated… When I’ve used arrays of arrays in another language all elements were used so there was no point to that.

Also if all I need to to do is iterate through the elements of each array in order, or who’s indices I already know, then dictionaries lookups are still more overhead and using them is kind of pointless… Never mind the overhead of object creation, which is inherent as variants are objects .

In general I am just concerned about the costs of the tendency towards everything needing to be an object to get things done.

As I mentioned elsewhere, computing power these days seem to be increasing by adding more cores rather than making the cores faster as in the old days… And Xojo apps (without helper apps) only use a single core.

Arrays of Arrays could be implemented under the hood to be very efficient both in execution and memory usage compared to other strategies…

But I can see now that this is likely to go nowhere.

I think arrays of arrays would be a pretty hefty change to the language and the runtime
So I have my doubts that it’d fly but you can always submit a request if there isn’t one already

Expensive in what way? Wouldn’t creating an array have similar overhead - they’re not just chunks of memory.