UE4 内存管理测试 FMemory

uint8*pdata = (uint8*)FMemory::Malloc(1024);
    FMemory::Memzero(pdata, 1024);
    uint32 size = (uint32)FMemory::GetAllocSize(pdata);
    UE_LOG(LogTemp, Warning, TEXT("内存大小{%d}!"), size);
    //LogTemp: Warning: 内存大小{1024}!
    UE_LOG(LogTemp, Warning, TEXT("字符串长度{%d}!"), FCStringAnsi::Strlen((ANSICHAR*)pdata));
    //LogTemp: Warning: 字符检测大小{0}!
    FString fs = TEXT("1234567890中国");
    FString fn = TEXT("abcdefg人");
    TCHAR*tt = fs.GetCharArray().GetData();
    uint8*ptmp = (uint8*)TCHAR_TO_UTF8(tt);
    int32 fslen = FCStringAnsi::Strlen((ANSICHAR*)ptmp);
    UE_LOG(LogTemp, Warning, TEXT("fs len{%d},{%d}"), fslen, FCString::Strlen(tt));
    //LogTemp: Warning: fs len{16},{12}
    FMemory::Memcpy(pdata, ptmp, fslen);
    UE_LOG(LogTemp, Warning, TEXT("copy 1 %s"), UTF8_TO_TCHAR(ptmp));
    //LogTemp: Warning: copy 1 1234567890中国
    UE_LOG(LogTemp, Warning, TEXT("字符串长度{%d}!"), FCStringAnsi::Strlen((ANSICHAR*)pdata));
    //LogTemp: Warning: 字符串长度{16}!
    tt = fn.GetCharArray().GetData();
    ptmp = (uint8*)TCHAR_TO_UTF8(tt);
    int32 fnlen = FCStringAnsi::Strlen((ANSICHAR*)ptmp);
    FMemory::Memcpy(pdata + fslen, ptmp, fnlen);
    UE_LOG(LogTemp, Warning, TEXT("copy 2 %s"), UTF8_TO_TCHAR(pdata));
    //LogTemp: Warning: copy 2 1234567890中国abcdefg人
    UE_LOG(LogTemp, Warning, TEXT("字符串长度{%d}!"), FCStringAnsi::Strlen((ANSICHAR*)pdata));
    //======================================================================
    FMemory::Memmove(pdata, pdata + 10, 8);
    UE_LOG(LogTemp, Warning, TEXT("copy 3 %s"), UTF8_TO_TCHAR(pdata));
    //LogTemp: Warning: copy 3 中国ab90中国abcdefg人
    FMemory::Memzero(pdata + 8, 18);
    UE_LOG(LogTemp, Warning, TEXT("copy 3 %s"), UTF8_TO_TCHAR(pdata));
    //LogTemp: Warning: copy 3 中国ab
    UE_LOG(LogTemp, Warning, TEXT("字符串3长度{%d}!"), FCStringAnsi::Strlen((ANSICHAR*)pdata));
    //LogTemp: Warning: 字符串3长度{8}!
    FMemory::Memmove(pdata, pdata + 3, 5);
    UE_LOG(LogTemp, Warning, TEXT("copy 4 %s"), UTF8_TO_TCHAR(pdata));
    //LogTemp: Warning: copy 4 国ab?ab
    UE_LOG(LogTemp, Warning, TEXT("字符串4长度{%d}!"), FCStringAnsi::Strlen((ANSICHAR*)pdata));
    //LogTemp: Warning: 字符串4长度{6}!
    FMemory::Memzero(pdata + 5, 3);
    UE_LOG(LogTemp, Warning, TEXT("copy 4 %s"), UTF8_TO_TCHAR(pdata));
    //LogTemp: Warning: copy 4 国ab
    UE_LOG(LogTemp, Warning, TEXT("字符串4长度{%d}!"), FCStringAnsi::Strlen((ANSICHAR*)pdata));
    //    //LogTemp: Warning: 字符串4长度{5}!
    FMemory::Free(pdata);

你可能感兴趣的:(测试,内存管理)