当前位置:网站首页>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 }
// ]边栏推荐
- From personal heroes to versatile developers, the era of programmer 3.0 is coming
- Using emqx cloud to realize one machine one secret verification of IOT devices
- Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
- Web side defense Guide
- 图像基础概念与YUV/RGB深入理解
- Market Research - current market situation and future development trend of third-party data platform
- LandingSite eBand B1冒烟测试用例
- 100 important knowledge points that SQL must master: using cursors
- Market Research - current situation and future development trend of carob chocolate market
- PHP微信抢红包的算法
猜你喜欢

New feature of go1.18: introduce new netip Network Library

Lightgbm principle and its application in astronomical data

Infrastructure is code: a change is coming

540. Single element in ordered array

基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习

Blue Bridge Cup Winter vacation homework (DFS backtracking + pruning)

What is it that makes you tremble? Those without fans can learn

Hanoi Tower problem

20220702-程序员如何构建知识体系?

Daily book CSO advanced road first exposed
随机推荐
CVPR论文解读 | 弱监督的高保真服饰模特生成
sql service 截取字符串
Pyqt picture decodes and encodes and loads pictures
Unity3d learning notes 4 - create mesh advanced interface
【剑指 Offer】57. 和为s的两个数字
Introduction to victoriametrics
pip安装whl文件报错:ERROR: ... is not a supported wheel on this platform
20220702 how do programmers build knowledge systems?
[001] [arm-cortex-m3/4] internal register
From "bronze" to "King", there are three secrets of enterprise digitalization
A week's life
Blue Bridge Cup Eliminate last one (bit operation, code completion)
【剑指 Offer 】56 - II. 数组中数字出现的次数 II
[staff] Sibelius 7.5.1 score software installation (software download | software installation)
Introduction to the principle of geographical detector
VIM command-t plugin error: unable to load the C extension - VIM command-t plugin error: could not load the C extension
Oriental Aesthetics and software design
Market Research - current market situation and future development trend of total nutrition products
地理探测器原理介绍
Daily book CSO advanced road first exposed