Распределение памяти между Java и C #
Есть Java проект который использует FileChannel и делит данные между двумя JVM, мне нужно получить доступ к этой памяти из C#. Проекты на Java
File f = new File("Путь к файлу");
FileChannel channel = FileChannel.open( f.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE );
MappedByteBuffer b = channel.map( FileChannel.MapMode.READ_WRITE, 0, 4096 );
CharBuffer charBuf = b.asCharBuffer();
char[] string = "Hello client\0".toCharArray();
charBuf.put( string );
System.out.println( "Waiting for client." );
while( charBuf.get( 0 ) != '\0' );
System.out.println( "Finished waiting." );
и
File f = new File( "Путь к файлу" );
FileChannel channel = FileChannel.open( f.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE );
MappedByteBuffer b = channel.map( FileChannel.MapMode.READ_WRITE, 0, 4096 );
CharBuffer charBuf = b.asCharBuffer();
// Prints 'Hello server'
char c;
while( ( c = charBuf.get() ) != 0 ) {
System.out.print( c );
}
System.out.println();
charBuf.put( 0, '\0' );
введите сюда код
На С# я пытають открыть файл так
MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile("Путь к файлу");
и получаю IOException. The process cannot access the file ... because it is being used by another process.