我正在使用JNotify项目来监听文件系统事件.这取决于每个OS的一个本机库:处理器架构.例如,有一个用于Windows x86的库,一个用于x86-64等的库.
最初,我有一个包含JNotify Java类和本机代码的包.本机代码在Bundle-NativeCode中声明如下:
(我已经将这些格式化为bnd样式以获得更好的可读性......显然,实际的MANIFEST.MF文件已正确形成).
Bundle-NativeCode: jnotify_64bit.dll;osname=Win32;osname="Windows NT (unknown)";osname = WindowsXP;osname = Windows2000;osname = Windows2003;osname = WindowsVista;osname = Windows7;osname = WindowsServer2008;osname= Windows8;osname = WindowsServer2012;processor = x86-64,\
jnotify.dll;osname=Win32;osname="Windows NT (unknown)";osname = WindowsXP;osname = Windows2000;osname = Windows2003;osname = WindowsVista;osname = Windows7;osname = WindowsServer2008;osname = Windows8;osname = WindowsServer2012;processor = x86,\
libjnotify.so;osname = Linux;processor = x86,\
libjnotify64.so;osname = Linux;processor = x86-64,\
libjnotify.dylib;osname = Mac OSX;processor = x86;processor = x86-64,\
*
Run Code Online (Sandbox Code Playgroud)
这很好用.
我认为如果我将库移动到单独的片段包中会很"好",这样我就可以为我感兴趣的体系结构贡献片段.以Linux为例,我将它们分成两个包:
Linux 32位
Include-Resource: lib/libjnotify.so
Bundle-NativeCode: libjnotify.so;osname = Linux;processor …Run Code Online (Sandbox Code Playgroud) 我无法理解:"为什么要这样保证?"
这是自定义本机函数的包装dart/runtime/vm/native_entry.cc:
它适用于想要写入的Dart程序员native extensions.
void NativeEntry::NativeCallWrapper(Dart_NativeArguments args,
Dart_NativeFunction func) {
CHECK_STACK_ALIGNMENT;
VERIFY_ON_TRANSITION;
NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
Isolate* isolate = arguments->isolate();
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
ApiLocalScope* current_top_scope = state->top_scope();
ApiLocalScope* scope = state->reusable_scope();
TRACE_NATIVE_CALL("0x%" Px "", reinterpret_cast<uintptr_t>(func));
if (scope == NULL) {
scope = new ApiLocalScope(current_top_scope,
isolate->top_exit_frame_info());
ASSERT(scope != NULL);
} else {
scope->Reinit(isolate,
current_top_scope,
isolate->top_exit_frame_info());
state->set_reusable_scope(NULL);
}
state->set_top_scope(scope); // New scope is now the top scope.
func(args);
ASSERT(current_top_scope == scope->previous());
state->set_top_scope(current_top_scope); // Reset …Run Code Online (Sandbox Code Playgroud) 我正在查看AtomicInteger类的Java源代码(在此处找到),以查看实现JVM所需的原子基元.我注意到他们使用未记录的UnsafeAPI来实现他们的原子整数操作,并且他们使用的唯一两个原语似乎是compare and swap和compare and set操作.而Unsafe类将这些指令实现为本机方法,这使我相信它们正在使用在一般情况下执行这些原始操作的本机指令.然而,并非每个处理器(尽管大多数现代处理器都有)具有本地支持这些原语的指令集.现在,即使没有本机处理器支持,这些原语也可以由VM实现,以保证与其他VM线程的原子性,但不一定与其他本机线程一致.那么java是否要求本机架构上的这些原语具有有效的JVM,因此所有JVM实现都支持本机线程的原子性,或者java中的原子性只保证在java线程之间?
Java原始对象映射到本机基元.
所以我的问题是如何char value[] = new char[0];表现?
它是否依赖于gcc编译器实现(本机代码)?这是否意味着所有空Java都String指向同一个地址?
我已经在stackoverflow上阅读了一些相关答案,但似乎没有人回答我的问题。我将从本机代码中获取android ID,即在C代码中调用方法getAndroidIDfromNativeCode,(因此JVM通过方法在本机代码中初始化create_vm),大家知道在调用getContentResolver方法时,必须使用一个Android Context实例来调用,那么如何获取这个Context实例呢?
static jstring
native_code_getAndroidID(JNIEnv *env, jobject thiz)
{
jclass c_settings_secure = (*env)->FindClass(env, "android/provider/Settings$Secure");
jclass c_context = (*env)->FindClass(env,"android/content/Context");
if(c_settings_secure == NULL || c_context == NULL){
return NULL;
}
//Get the getContentResolver method
jmethodID m_get_content_resolver = (*env)->GetMethodID(env, c_context, "getContentResolver",
"()Landroid/content/ContentResolver;");
if(m_get_content_resolver == NULL){
return NULL;
}
//Get the Settings.Secure.ANDROID_ID constant
jfieldID f_android_id = (*env)->GetStaticFieldID(env, c_settings_secure, "ANDROID_ID", "Ljava/lang/String;");
if(f_android_id == NULL){
return NULL;
}
jstring s_android_id = (*env)->GetStaticObjectField(env, c_settings_secure, f_android_id);
//create a ContentResolver instance context.getContentResolver() …Run Code Online (Sandbox Code Playgroud) Dotnet CLR将语言代码转换为MSIL.将Java代码转换为独立于平台的本机代码.我们可以将此MSIL转换为本机代码吗?因此,Dotnet将自动变为独立于平台.
我面临着实现一个IDispatch接口。有四种方法,幸运的是其中 3 种方法很简单:
function TIEEventsSink.GetTypeInfoCount(...): HResult;
{
Result := E_NOTIMPL;
}
function TIEEventsSink.GetTypeInfo(...): HResult;
{
Result := E_NOTIMPL;
}
function TIEEventsSink.GetIDsOfNames(...): HResult;
{
Result := E_NOTIMPL;
}
Run Code Online (Sandbox Code Playgroud)
这是最后一种方法,Invoke这很困难。在这里,我不得不实际处理DispID并调用我的适当方法;从变体数组解组参数。
function Invoke(
dispIdMember: DISPID;
riid: REFIID;
lcid: LCID;
wFlags: WORD;
var pDispParams: DISPPARAMS;
var pVarResult: VARIANT;
var pExcepInfo: EXCEPINFO;
var puArgErr: DWORD
): HRESULT;
Run Code Online (Sandbox Code Playgroud)
不想编写所有乏味的样板代码,我肯定会有错误,我去谷歌搜索 - 而不是做任何工作。
我在以下的 MSDN 文档中IDispatch.Invoke找到了这个片段:
通常,您不应直接实现Invoke。
优秀!我无论如何都不想实施它!继续阅读:
相反,使用调度接口来创建函数CreateStdDispatch和DispInvoke。有关详细信息,请参阅CreateStdDispatch、DispInvoke、 …
我正在尝试使用一些本地代码来创建Gif.我使用绘画绘制图像,创建几个笔划,单击保存,绘制的图像将保存为JPG格式.当我点击创建Gif时,它会获取所有图像并开始创建一个gif.这是当我得到致命信号11并且应用程序重新启动时.
我使用本机代码,所以我有崩溃的回溯:
I/DEBUG(95): backtrace:
I/DEBUG(95): #00 pc 00002a04 /lib/libgifflen.so (NeuQuant::learn()+239)
I/DEBUG(95): #01 pc 00002b9d /lib/libgifflen.so (NeuQuant::quantise(DIB*, DIB*, int, int, int)+84)
I/DEBUG(95): #02 pc 00002d41 lib/libgifflen.so (Java_com_stay_gif_GifEncoder_addFrame+208)
I/DEBUG(95): #03 pc 0001deb0 /system/lib/libdvm.so (dvmPlatformInvoke+112)
I/DEBUG(95): #04 pc 0004d103 /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+394)
I/DEBUG(95): #05 pc 0004f21f /system/lib/libdvm.so (dvmResolveNativeMethod(unsigned int const*, JValue*, Method const*, Thread*)+174)
I/DEBUG(95): #06 pc 000272e0 /system/lib/libdvm.so
I/DEBUG(95): #07 pc 0002bbe8 /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+180)
I/DEBUG(95): #08 pc 0005fb37 /system/lib/libdvm.so (dvmInvokeMethod(Object*, Method const*, ArrayObject*, ArrayObject*, …Run Code Online (Sandbox Code Playgroud) 我很无聊,所以我开始在控制台中摆弄,并偶然发现了这个(忽略语法错误):

我不确定这是否应该是一个单独的问题,但我实际上是在尝试将数字四舍五入到小数点后的某个数量。我研究了一下,发现了两种方法:
>方法一
function roundNumber(number, digits) {
var multiple = Math.pow(10, digits);
return Math.floor(number * multiple) / multiple;
}
Run Code Online (Sandbox Code Playgroud)
>方法 B
function roundNumber(number, digits) {
return Number(number.toFixed(digits));
}
Run Code Online (Sandbox Code Playgroud)
直觉上我更喜欢方法B(看起来更有效),但我不知道幕后发生了什么,所以我无法判断。有人对此有什么想法吗?或者一种对此进行基准测试的方法?为什么没有原生的 round_to_this_many_decimals 函数?(返回一个整数,而不是一个字符串)
我搜索了许多文档,但没有找到任何针对我的问题的确切解决方案。我想在不使用任何第三方 sdk 的情况下使用 webrtc 在 Android 本机应用程序中实现音频通话和屏幕共享。
我找到了一个演示示例,即 apprtc,但它仅支持音频通话。如何实现屏幕共享?
native-code ×10
java ×5
android ×3
.net ×1
android-ndk ×1
arrays ×1
atomic ×1
c++ ×1
char ×1
cil ×1
com ×1
dart ×1
fatal-error ×1
gif ×1
idispatch ×1
javascript ×1
jvm ×1
osgi ×1
performance ×1
rounding ×1
string ×1
webrtc ×1
winapi ×1