当前位置:网站首页>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 }
// ]边栏推荐
- 记录一下微信、QQ、微博分享web网页功能
- The book "new programmer 002" is officially on the market! From "new database era" to "software defined car"
- 【C 题集】of Ⅴ
- ServiceMesh主要解决的三大痛點
- 100 important knowledge points that SQL must master: using cursors
- APP页面分享口令Rails实现
- Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
- 一周生活
- 基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
- SQL必需掌握的100个重要知识点:管理事务处理
猜你喜欢

分享一下如何制作专业的手绘电子地图

Pip install whl file Error: Error: … Ce n'est pas une roue supportée sur cette plateforme
![[staff] Sibelius 7.5.1 score software installation (software download | software installation)](/img/1a/4932a7931c54248c065cf8a1462d34.jpg)
[staff] Sibelius 7.5.1 score software installation (software download | software installation)

Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale

New feature of go1.18: introduce new netip Network Library
![[001] [arm-cortex-m3/4] internal register](/img/49/a0eceac1a67267216dd9b2566033a1.jpg)
[001] [arm-cortex-m3/4] internal register

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

Redis distributed lock failure, I can't help but want to burst

Official announcement! The golden decade of new programmers and developers was officially released

Introduction to the principle of geographical detector
随机推荐
[shutter] shutter layout component (wrap component | expanded component)
APP页面分享口令Rails实现
【C 题集】of Ⅴ
The difference between include < > and include ""
腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
20220702-程序员如何构建知识体系?
New feature of go1.18: trylock, which has been tossed n times
2019 Nanchang (relive the classic)
Market Research - current market situation and future development trend of aircraft audio control panel system
Bridge emqx cloud data to AWS IOT through the public network
[staff] Sibelius 7.5.1 score software installation (software download | software installation)
The source code of the daily book analyzes the design idea of Flink and solves the problems in Flink
Share how to make professional hand drawn electronic maps
Ransack combined condition search implementation
CVPR论文解读 | 弱监督的高保真服饰模特生成
An overview of the development of affective computing and understanding research
sql service 截取字符串
From "bronze" to "King", there are three secrets of enterprise digitalization
基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
ServiceMesh主要解决的三大痛点