当前位置:网站首页>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与AddUninitializedandInsertUninitialized函数一样,如果需要,您应该确保将新元素正确构建到新空间中:
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 }
// ]边栏推荐
- pip安装whl文件报错:ERROR: ... is not a supported wheel on this platform
- Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
- Five message formats of OSPF
- 腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
- Une semaine de vie
- 关于PHP-数据库的 数据读取,Trying to get property 'num_rows' of non-object?
- Landingsite eband B1 smoke test case
- scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
- C语言,实现三子棋小游戏
- C language, to achieve three chess games
猜你喜欢

A specially designed loss is used to deal with data sets with unbalanced categories

"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba

Pointer and string

*C language final course design * -- address book management system (complete project + source code + detailed notes)

"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
![[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)](/img/27/8594ba0b49d5008b7469967babed17.jpg)
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)

New feature of go1.18: trylock, which has been tossed n times

Scrcpy this software solves the problem of sharing mobile screen with colleagues | community essay solicitation

《Just because》阅读感受

Blue Bridge Cup Winter vacation homework (DFS backtracking + pruning)
随机推荐
Market Research - current market situation and future development trend of intravenous injection (IV) bottles
Market Research - current situation and future development trend of herringbone gear Market
[leetcode] sword finger offer 11 Rotate the minimum number of the array
Record the functions of sharing web pages on wechat, QQ and Weibo
[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)
Image segmentation using pixellib
Try to get property'num for PHP database data reading_ rows' of non-object?
【C 题集】of Ⅴ
Official announcement! The golden decade of new programmers and developers was officially released
Learn computer knowledge from scratch
Market Research - current situation and future development trend of cell-based seafood market
Blue Bridge Cup Eliminate last one (bit operation, code completion)
SQL必需掌握的100个重要知识点:使用游标
Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
《Just because》阅读感受
[shutter] shutter gesture interaction (small ball following the movement of fingers)
Technical solution of vision and manipulator calibration system
Market Research - current market situation and future development trend of marine wet exhaust hose
SQL必需掌握的100个重要知识点:管理事务处理