Question

I would like to write char* buf[] to shared memory.

I got several pointer to several maps - char* m_pP[MAX], maps are opened

m_oMMF[channel] = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, wstring);
m_pP[channel] = (char*) MapViewOfFile(m_oMMF[channel], FILE_MAP_ALL_ACCESS, 0, 0, size);

size of map is big enough, I got int offset where I wanna to write in shared memory using this m_P[] pointer but I am struggling at the syntax of this.

Im not so experienced in C++. Can anyone help me with this?

Thanks

Was it helpful?

Solution

Not sure If I understood clearly.

But I assume, you have character pointer pointing to mapped memory and you are trying to write data after certain offset.

char * ptr_to_memory = m_pP[channel];

//buf is array of character pointer, so you need to know the "index" as well as "size" of the data you need to write.

char * data_to_write = buf[index];

memcpy( ptr_to_memory + offset, data_to_write, size );

Remember to do some sanity check, whether ( ptr + offset ) is within the mapped region.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top