当前位置:网站首页>U++ 原始内存 学习笔记
U++ 原始内存 学习笔记
2022-07-02 22:01:00 【是秃头的兔子呀】
AddUninitialized
和
InsertUninitialized
函数将向数组添加一些未初始化的空间。它们分别像Add
和Insert
函数一样工作,但它们不会调用元素类型的构造函数。这对于避免调用构造函数很有用。Memcpy
您可能会在以下示例中执行此操作,您计划使用调用 覆盖整个结构:
int32 SrcInts[] = { 2, 3, 5, 7 };
TArray<int32> UninitInts;
UninitInts.AddUninitialized(4);
FMemory::Memcpy(UninitInts.GetData(), SrcInts, 4*sizeof(int32));
// UninitInts == [2,3,5,7]
您还可以使用此功能为您计划自己构建的对象保留内存:
TArray<FString> UninitStrs;
UninitStrs.Emplace(TEXT("A"));
UninitStrs.Emplace(TEXT("D"));
UninitStrs.InsertUninitialized(1, 2);
new ((void*)(UninitStrs.GetData() + 1)) FString(TEXT("B"));
new ((void*)(UninitStrs.GetData() + 2)) FString(TEXT("C"));
// UninitStrs == ["A","B","C","D"]
AddZeroed
并且InsertZeroed
工作类似,除了它们还将添加/插入空间的字节归零:
struct S
{
S(int32 InInt, void* InPtr, float InFlt)
: Int(InInt)
, Ptr(InPtr)
, Flt(InFlt)
{
}
int32 Int;
void* Ptr;
float Flt;
};
TArray<S> SArr;
SArr.AddZeroed();
// SArr == [{ Int: 0, Ptr: nullptr, Flt: 0.0f }]
除了新SetNumUninitialized
的数字大于当前的数字,新元素的空间将分别保持未初始化或按位归零SetNumZeroed
。SetNum
与AddUninitialized
andInsertUninitialized
函数一样,如果需要,您应该确保将新元素正确构建到新空间中:
SArr.SetNumUninitialized(3);
new ((void*)(SArr.GetData() + 1)) S(5, (void*)0x12345678, 3.14);
new ((void*)(SArr.GetData() + 2)) S(2, (void*)0x87654321, 2.72);
// SArr == [
// { Int: 0, Ptr: nullptr, Flt: 0.0f },
// { Int: 5, Ptr: 0x12345678, Flt: 3.14f },
// { Int: 2, Ptr: 0x87654321, Flt: 2.72f }
// ]
SArr.SetNumZeroed(5);
// SArr == [
// { Int: 0, Ptr: nullptr, Flt: 0.0f },
// { Int: 5, Ptr: 0x12345678, Flt: 3.14f },
// { Int: 2, Ptr: 0x87654321, Flt: 2.72f },
// { Int: 0, Ptr: nullptr, Flt: 0.0f },
// { Int: 0, Ptr: nullptr, Flt: 0.0f }
// ]
边栏推荐
- An overview of the development of affective computing and understanding research
- sql service 截取字符串
- 【leetcode】1380. Lucky number in matrix
- App page sharing password rails implementation
- 技术人创业:失败不是成功,但反思是
- "New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
- Micro service gateway selection, please accept my knees!
- Pointer and string
- Error in PIP installation WHL file: error: is not a supported wheel on this platform
- Perceptron model and Application
猜你喜欢
Blue Bridge Cup Winter vacation homework (DFS backtracking + pruning)
[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)
pip安裝whl文件報錯:ERROR: ... is not a supported wheel on this platform
Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
Off chip ADC commissioning record
Daily book CSO advanced road first exposed
TinyMCE visual editor adds Baidu map plug-in
"Actbert" Baidu & Sydney University of technology proposed actbert to learn the global and local video text representation, which is effective in five video text tasks!
How to write a good program when a big book speaks every day?
From "bronze" to "King", there are three secrets of enterprise digitalization
随机推荐
Chargement de l'image pyqt après décodage et codage de l'image
Redis distributed lock failure, I can't help but want to burst
Off chip ADC commissioning record
Image segmentation using pixellib
Pointer - function pointer
使用 EMQX Cloud 实现物联网设备一机一密验证
[shutter] shutter layout component (wrap component | expanded component)
一周生活
Blue Bridge Cup Eliminate last one (bit operation, code completion)
【C 题集】of Ⅴ
ServiceMesh主要解决的三大痛點
tinymce可视化编辑器增加百度地图插件
"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
[shutter] shutter page Jump (route | navigator | page close)
Evolution of messaging and streaming systems under the native tide of open source cloud
How to write a good program when a big book speaks every day?
20220702 how do programmers build knowledge systems?
About test cases
Web side defense Guide
Market Research - current market situation and future development trend of genome editing mutation detection kit