Remix.run Logo
narag an hour ago

I found a solution for what seems to be the same problem, in a different language: a particular type of lists, where the class metadata is stored once and the data for each instance is contiguously stored in a flat array.

Not sure if it covers exactly the same terrain, but perusing the article, it seems to be the case, with a single instance being the degenerate case.

cogman10 an hour ago | parent [-]

Yup, it's the same terrain.

I've made something like this in the past. And I did it exactly because `List<Foo>` was too expensive and slow.

    class FooSOA extends Collection<Foo> {
      double x[];
      double y[];
      double z[];
      
      Foo get(int index) { return new Foo(index); }
      
      record Foo(int index) {
        double x() { return FooSOA.this.x[i]; }
        double y() { return FooSOA.this.y[i]; }
        double z() { return FooSOA.this.z[i]; }
      }
    }