を避ける
// 1024Byte確保される
Memory buff = new Memory(1024);
boolean hasNext = true;
StringBuffer sb = new StringBuffer();
while(hasNext){
Memory buff = new Memory(1024); // おもい
hasNext = AwsomeApi(buff);
sb.append(buff.getWideString(0));
}
boolean hasNext = true;
StringBuffer sb = new StringBuffer();
Memory buff = new Memory(1024); // おもい
while(hasNext){
buff.clear() // ゼロクリア
hasNext = AwsomeApi(buff);
sb.append(buff.getWideString(0));
}
// Pointerサイズ分mallocされる
Memory buff = new Memory();
で変数の値を読み込むのを避ける
struct TestStruct {
long long longLongValue;
void* voidPointerValue;
TestStruct *structPointerValue;
};
public class TestStruct extends Structure {
public long longLongValue;
public Pointer voidPointerValue;
public TestStruct.ByReference structPointerValue;
public TestStruct() {
super();
}
...
}
Memory buff = new Memory(1024);
AwesomeApi(buff);
TestStruct testStruct = new TestStruct(buff);
// 全フィールドをnativeから読み込んでしまう
testStruct.read()
long nanika = testStruct.longLongValue;
native
heap
Memory buff = new Memory(1024);
AwesomeApi(buff);
TestStruct testStruct = new TestStruct(buff);
// longだけnativeから読み込む
testStruct.readField("longLongValue")
long nanika = testStruct.longLongValue;
native
heap
typedef struct _EVT_VARIANT {
union {
BOOL BooleanVal;
INT8 SByteVal;
INT16 Int16Val;
INT32 Int32Val;
INT64 Int64Val;
UINT8 ByteVal;
UINT16 UInt16Val;
UINT32 UInt32Val;
UINT64 UInt64Val;
float SingleVal;
double DoubleVal;
ULONGLONG FileTimeVal;
SYSTEMTIME *SysTimeVal;
GUID *GuidVal;
LPCWSTR StringVal;
LPCSTR AnsiStringVal;
PBYTE BinaryVal;
PSID SidVal;
size_t SizeTVal;
EVT_HANDLE EvtHandleVal;
BOOL *BooleanArr;
INT8 *SByteArr;
INT16 *Int16Arr;
INT32 *Int32Arr;
INT64 *Int64Arr;
UINT8 *ByteArr;
UINT16 *UInt16Arr;
UINT32 *UInt32Arr;
UINT64 *UInt64Arr;
float *SingleArr;
double *DoubleArr;
FILETIME *FileTimeArr;
SYSTEMTIME *SysTimeArr;
GUID *GuidArr;
LPWSTR *StringArr;
LPSTR *AnsiStringArr;
PSID *SidArr;
size_t *SizeTArr;
LPCWSTR XmlVal;
LPCWSTR* XmlValArr;
};
DWORD Count;
DWORD Type;
} EVT_VARIANT, *PEVT_VARIANT;