How to create array “meta” dynamically?

I can get the array element type during run time
Var arr_element_type: Type := GetElementType();

Then how can I use the element type to creat dynamic array?

Var arr := new arr_element_type[100] is obviously not a valid statement

Advice? @ck

you can’t create an array from it’s element type, but you could create it from it’s full type. Can you explain what your goal is here?

My situation is

  • The type of the array element is obtained during run time
  • Creat a dynamic array out of that type
  • Use memcpy to read a number of raw bytes into the newly created array

It is like the element type and raw bytes are saved to disk, and I am loading the data back to a typed dynamic array.

I can use a big case-switch but I’d like to know if there is any smarter way.

Can you use a generic type for this instead of reflection?

The problem is that you can’t really “construct” a generic type (and int[] is an Array<Int> internally) at runtime, as it’s a completely distinct type.

Understand. Thank you for the heads up.