当前位置:网站首页>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 }
// ]边栏推荐
- Daily book -- analyze the pain points of software automation from simple to deep
- scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
- Market Research - current market situation and future development trend of third-party data platform
- :last-child 不生效解决
- Infrastructure is code: a change is coming
- PIP audit: a powerful security vulnerability scanning tool
- Market Research - current situation and future development trend of cell-based seafood market
- 【leetcode】1380. Lucky number in matrix
- APP页面分享口令Rails实现
- 【剑指 Offer】56 - I. 数组中数字出现的次数
猜你喜欢

The book "new programmer 002" is officially on the market! From "new database era" to "software defined car"

"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!

The difference between include < > and include ""

Introduction to the principle of geographical detector

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

LandingSite eBand B1冒烟测试用例

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

PIP audit: a powerful security vulnerability scanning tool

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

sql service 截取字符串
随机推荐
100 important knowledge points that SQL must master: management transaction processing
The difference between include < > and include ""
C语言,实现三子棋小游戏
[shutter] shutter layout component (wrap component | expanded component)
[staff] Sibelius 7.5.1 score software installation (software download | software installation)
[Jianzhi offer] 57 And are two numbers of S
Image segmentation using pixellib
[shutter] shutter application theme (themedata | dynamic modification theme)
Market Research - current situation and future development trend of environmental friendly fireworks Market
pip安裝whl文件報錯:ERROR: ... is not a supported wheel on this platform
Market Research - current market situation and future development trend of high tibial osteotomy plate
[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)
100 important knowledge points that SQL must master: using cursors
SQL必需掌握的100个重要知识点:管理事务处理
Market Research - current situation and future development trend of carob chocolate market
一周生活
Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
Market Research - current market situation and future development trend of aircraft audio control panel system
kubernetes资源对象介绍及常用命令(四)
【C 题集】of Ⅴ