Kakushi_52
(Kakushi_52)
November 2, 2017, 3:43am
1
TArray::Append copies the raw memory from std::vector to TArray.
I am now dealing with huge size of std::vector so I’d like to “reference” the element of the std::vector to TArray, like,
std::vector<int> vec_test{1,2,3,4,5};
TArray<int> tarray_test;
tarray_test.Reserve(vec_test.size());
tarray_test.GetData() = vec_test.data();
I know
tarray_test.GetData() = vec_test.data();
is impossible, but is there any way to do like this?
Maybe, some Allocator helps??
MC3366
(MC3366)
November 26, 2022, 1:58pm
2
Although it seems to be long time ago, I just reply here in case someone need it.
FMemory::Memcpy(<std::vector>.data(), <TArray>.GetData(), <TArray>.Num()*sizeof(int));
There’s TArrayView
as well. If you don’t want to modify the std::vector you should be able to pass its data and size as the arguments to the constructor of TArrayView (or use MakeArrayView
). https://github.com/EpicGames/UnrealEngine/blob/cdaec5b33ea5d332e51eee4e4866495c90442122/Engine/Source/Runtime/Core/Public/Containers/ArrayView.h#L122