Hi
I want to copy a string data to shared memory multiple times using CopyMemory(). But this call only keeps the last string data and clears the existing one. Ofcourse this is as per the design. But will some one let me know how to copy the string data to shared memory using any other alternate api which should not override the existing data.
I have a std::string which has almost 5Lakh characters in it. When i try to copy that string to shared memory it is crashing
HANDLE hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, BUF_SIZE, wstring{ L"Local\\StringData_" + to_wstring(GetParentID()) }.data());
m_pStringBuf = (LPCTSTR)MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, BUF_SIZE);
CopyMemory((PVOID)m_pStringBuf, st.data(), (st.size()+1) * sizeof(TCHAR));
Instead of copying the st.data() at a time, i want to copy the data when ever i get it so that the string holds less data and no crash occurs.
Any suggestions please.
What I have tried:
Tried self and googled but dint not find right answer.
What is wrong here which is crashing at CopyMemory()
std::string m_strData;
std::string ch = "s";
for (long long i = 0; i < 500000; i++)
{
m_strData.append(ch);
}
long BUF_SIZE = (long)(sizeof(TCHAR) * (m_strData.size() + 1));
HANDLE hMapFilesize = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(long), { L"Local\\AECData_BufferSize_" });
long *m_pAECBufferSize = reinterpret_cast<long*>(MapViewOfFile(hMapFilesize, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(long)));
CopyMemory((PVOID)m_pAECBufferSize, &BUF_SIZE, sizeof(long));
HANDLE hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, BUF_SIZE, { L"Local\\AECPropertiesAndLinkages_" });
LPTSTR m_pAECQuantityBuf = (LPTSTR)MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, BUF_SIZE);
CopyMemory((PVOID)m_pAECQuantityBuf, m_strData.data(), (m_strData.size() + 1) * sizeof(TCHAR));