UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MemStackUtility.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
5#include "Misc/MemStack.h"
9
10namespace UE
11{
12namespace MemStack
13{
14
16{
17 TCHAR* Result = New<TCHAR>(Allocator, Length + 1);
18 FMemory::Memcpy(Result, String, Length * sizeof(TCHAR));
19 Result[Length] = 0;
20 return Result;
21}
22
24{
25 return AllocateString(Allocator, String.GetData(), String.Len());
26}
27
32
33inline const TCHAR* AllocateString(FMemStackBase& Allocator, const FStringBuilderBase& StringBuilder)
34{
35 return AllocateString(Allocator, StringBuilder.GetData(), StringBuilder.Len());
36}
37
38template <typename FormatType, typename... ArgTypes>
39inline const TCHAR* AllocateStringf(FMemStackBase& Allocator, const FormatType& Format, ArgTypes... Args)
40{
42 String.Appendf(Format, Forward<ArgTypes>(Args)...);
44}
45
46template <typename FormatType, typename... ArgTypes>
48{
50 String.Appendf(Format, Forward<ArgTypes>(Args)...);
51 return AllocateStringView(Allocator, String.ToView());
52}
53
54template<typename T>
56{
57 T* Data = nullptr;
58 if (View.Num() > 0)
59 {
60 Data = new(Allocator) T[View.Num()];
61 for (int32 i = 0; i < View.Num(); ++i)
62 {
63 Data[i] = View[i];
64 }
65 }
66 return MakeArrayView(Data, View.Num());
67}
68
69} // namespace MemStack
70} // namespace UE
constexpr auto MakeArrayView(OtherRangeType &&Other)
Definition ArrayView.h:873
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
TStringView< TCHAR > FStringView
Definition StringFwd.h:45
Definition MemStack.h:78
Definition ArrayView.h:139
UE_FORCEINLINE_HINT constexpr SizeType Num() const
Definition ArrayView.h:380
CharType * GetData() UE_LIFETIMEBOUND
Definition StringBuilder.h:120
int32 Len() const
Definition StringBuilder.h:114
Definition StringBuilder.h:509
TArrayView< T > AllocateArrayView(FMemStackBase &Allocator, TArrayView< T > View)
Definition MemStackUtility.h:55
const TCHAR * AllocateStringf(FMemStackBase &Allocator, const FormatType &Format, ArgTypes... Args)
Definition MemStackUtility.h:39
FStringView AllocateStringView(FMemStackBase &Allocator, FStringView String)
Definition MemStackUtility.h:28
FStringView AllocateStringViewf(FMemStackBase &Allocator, const FormatType &Format, ArgTypes... Args)
Definition MemStackUtility.h:47
const TCHAR * AllocateString(FMemStackBase &Allocator, const TCHAR *String, int32 Length)
Definition MemStackUtility.h:15
Definition AdvancedWidgetsModule.cpp:13
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160