第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Buffer.BlockCopy Array 2d c++ 到 C# 共享內(nèi)存

Buffer.BlockCopy Array 2d c++ 到 C# 共享內(nèi)存

C#
MMMHUHU 2022-07-23 17:48:17
我編寫了一個(gè) c++ 程序,它通過(guò) memorystream 將數(shù)組 multi 發(fā)送到 c# 應(yīng)用程序。但我不知道如何使用 BlockCopy 來(lái)排列多:這是我的程序 C++ 發(fā)送數(shù)組多struct Pair {    std::pair<int, int> players;};struct Pair* p;HANDLE handle;float dataSend[70];bool startShare(){    try    {        handle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(Pair), L"DataSend");        p = (struct Pair*) MapViewOfFile(handle, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, sizeof(Pair));        return true;    }    catch (...)    {        return false;    }}for (int i = 0; i < 70; i++){    int r1 = rand() % 10 + 1;    int r2 = rand() % 10 + 1;    p->players = { r1,r2 };}示例輸出: players  0 - [10][2] players  1 - [100][22] players 2 - [1][26] players 3 - [50][211] players 4 - [32][23]我的 C# 程序讀?。簆ublic static int[,] data = new int[70, 1];public static MemoryMappedFile mmf;public static MemoryMappedViewStream mmfvs;static public bool MemOpen(){    try    {        mmf = MemoryMappedFile.OpenExisting("DataSend");        mmfvs = mmf.CreateViewStream();        return true;    }    catch    {        return false;    }}// here need be somethings like   byte[,] bPosition = new byte[70,1];byte[] bPosition = new byte[70];mmfvs.Read(bPosition, 0, 100);Buffer.BlockCopy(bPosition, 0, data, 0, bPosition.Length); for (int i = 0; i< data.Length; i++) {    for(int j=0;j<1;j++)    {      Console.WriteLine(data[i][j]);    }}示例接收: data  0 - [10][2] data  1 - [100][22] data 2 - [1][26] data 3 - [50][211] data 4 - [32][23]我編寫了一個(gè) c++ 程序,它通過(guò) memorystream 將數(shù)組 multi 發(fā)送到 c# 應(yīng)用程序。但我不知道如何使用 BlockCopy 來(lái)排列多:這是我的程序 C++ 發(fā)送數(shù)組多
查看完整描述

1 回答

?
狐的傳說(shuō)

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超3個(gè)贊

嘗試以下:


              MemoryStream stream = new MemoryStream();

              byte[] buffer = new byte[70 * 2 * sizeof(int)];

              stream.Read(buffer, 0, 70 * 2 * sizeof(int));

              for (int i = 0; i< 70; i++)

              {

                  for (int j = 0; j < 2; j++)

                  {

                      Console.WriteLine(BitConverter.ToUInt32(buffer,(i * 2 * sizeof(int)) + (j * sizeof(int))));

                  }

              }

           IntPtr bufferPtr = Marshal.AllocHGlobal(BUFFER_SIZE);


            //you need to allocate memory before calling the routing


            byte[] buffer = new byte[BUFFER_SIZE];

            Marshal.Copy(bufferPtr, buffer, 0, BUFFER_SIZE);

            for (int i = 0; i < 70; i++)

            {

                for (int j = 0; j < 2; j++)

                {

                    Console.WriteLine(BitConverter.ToUInt32(buffer, (i * 2 * sizeof(int)) + (j * sizeof(int))));

                }

            }


            //method 2

            int[,] array = new int[40, 2];

            IntPtr bufferPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(array));


            //call routine then you code below to fill managed memory.

            Marshal.PtrToStructure(bufferPtr2, array);


查看完整回答
反對(duì) 回復(fù) 2022-07-23
  • 1 回答
  • 0 關(guān)注
  • 196 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)