Download

Fastest way to load raw memory into a T-Array?

I Have a block of bytes in memory, for which i have a pointer to the first byte in the block.
I would like to convert the block of bytes to a TArray of bytes.

I could make a new Tarray, and add each byte to it in a for loop however I am wondering, is there is a faster way?

There’s a TArray constructor that takes in the data + size and copies it in during creation.



TArray<char> MyArray(DataToRead, DataSize);


Alternatively you can just resize + memcpy yourself:



TArray<char> MyArray;
MyArray.Reserve(DataSize);
FMemory::Memcpy(MyArray.GetData(), DataToRead, DataSize);


Awesome, thankyou!