There is a C # Shared memory class on the Web, but the functionality is too simple, and write memory is written every time from the beginning. Therefore, this has been improved, and made a small example for the needs of the people for reference.
Main improvement points:
Complete memory Read and write functionality by taking advantage of part of the shared memory (hereinafter referred to as the "Data Information area") to store the data information stored in the current memory (count and length or add additional information).
When reading and writing memory, read and write the data information area.
1. Write Shared memory
Writes backward based on the current usage length of shared memory.
2. Read Shared memory
Reads all data from the starting position of the shared memory (excluding the data information area) to length.
3. Key points
The IntPtr type M_pwdata is manipulated as a pointer to enable the data to be read and written from any location in memory.
M_pwdatawrite = (INTPTR) (M_pwdata.gethashcode () + m_length + infosize);
4. Can improve the office
In the data information area, the length information of each piece of data is added to enable the free reading of the data without having to start reading every time.
The example screenshot is as follows: