[java][windows]共有メモリ - ファイルマッピング
2008/10/27
java
jni
win32
Javaです。windowsです。JNIで共有メモリです。
ファイルマッピングを使ってです。
ソースコード参考(まんまですが....)
動作させていません。(>_<)!
static {
System.loadLibrary("WindowsSharedMemory");
};
public native int CreateFileMapping();
public native int MapViewOfFile(int handle);
public native int ReadMemory(int addr);
public native int WriteMemory(int addr, int data);
public native boolean CloseMemory(int handle, int addr);
System.loadLibrary("WindowsSharedMemory");
};
public native int CreateFileMapping();
public native int MapViewOfFile(int handle);
public native int ReadMemory(int addr);
public native int WriteMemory(int addr, int data);
public native boolean CloseMemory(int handle, int addr);
JNIのコード
#include <windows.h>
#include "jni.h"
JNIEXPORT jint JNICALL Java_WindowsSharedMemory_CreateFileMapping(JNIEnv *env, jobject obj) {
return((jint)CreateFileMapping((HANDLE)0xFFFFFFFF, NULL,
PAGE_READWRITE, 0, 0x100, "SharedMemory"));
};
JNIEXPORT jint JNICALL Java_WindowsSharedMemory_MapViewOfFile(JNIEnv *env, jobject obj, jint handle) {
return((jint)MapViewOfFile((HANDLE)handle, FILE_MAP_ALL_ACCESS, 0, 0, 0));
};
JNIEXPORT jint JNICALL Java_WindowsSharedMemory_ReadMemory(JNIEnv *env, jobject obj, jint addr) {
return((jint)(*(unsigned char *)addr));
};
JNIEXPORT jint JNICALL Java_WindowsSharedMemory_WriteMemory(JNIEnv *env, jobject obj, jint addr, jbyte data) {
return(*((unsigned char *)addr) = data);
};
JNIEXPORT jboolean JNICALL Java_WindowsSharedMemory_CloseMemory(JNIEnv *env, jobject obj, jint handle, jint addr) {
UnmapViewOfFile((void *)addr);
return((jboolean)CloseHandle((HANDLE)handle));
};
#include "jni.h"
JNIEXPORT jint JNICALL Java_WindowsSharedMemory_CreateFileMapping(JNIEnv *env, jobject obj) {
return((jint)CreateFileMapping((HANDLE)0xFFFFFFFF, NULL,
PAGE_READWRITE, 0, 0x100, "SharedMemory"));
};
JNIEXPORT jint JNICALL Java_WindowsSharedMemory_MapViewOfFile(JNIEnv *env, jobject obj, jint handle) {
return((jint)MapViewOfFile((HANDLE)handle, FILE_MAP_ALL_ACCESS, 0, 0, 0));
};
JNIEXPORT jint JNICALL Java_WindowsSharedMemory_ReadMemory(JNIEnv *env, jobject obj, jint addr) {
return((jint)(*(unsigned char *)addr));
};
JNIEXPORT jint JNICALL Java_WindowsSharedMemory_WriteMemory(JNIEnv *env, jobject obj, jint addr, jbyte data) {
return(*((unsigned char *)addr) = data);
};
JNIEXPORT jboolean JNICALL Java_WindowsSharedMemory_CloseMemory(JNIEnv *env, jobject obj, jint handle, jint addr) {
UnmapViewOfFile((void *)addr);
return((jboolean)CloseHandle((HANDLE)handle));
};
: