Assignment Operations and TArrays

I have some very large TArrays that I’m filling with data, and then passing to another class. I’d like the data stored in the TArrays to exist in only one place, because of the sheer amount of data. When passing the TArray to the object, I want to assign it to a local member variable, so I can permanently access it.

The problem is, that in my understand, the TArray assignment operator creates a full separate copy of the array. Is there any way to simply have the member array reference the single master array, without taking the time and memory of duplicating it? Would this require using pointers, or is there another way to do it?

Hi,

You cannot make TArray point at a block of memory it didn’t allocate itself.

However, you could make use of TArrayView instead, which contains a pointer and size, and is constructible from a pointer and size. It has the API of TArray, but no length-mutation functions (e.g. Add(), Remove()).

Hope this helps,

Steve

Thank you, that’s exactly what I was looking for!