例如:
function A(){}
function B(){}
B.prototype = new A();
Run Code Online (Sandbox Code Playgroud)
如何检查B类是否继承A类?
当我尝试显示该功能时,我只获得[功能]:
> var a = function(){ return 'toto'; }
undefined
> a
[Function]
> require('util').inspect(a)
'[Function]'
Run Code Online (Sandbox Code Playgroud) 我正在http://learnyousomeerlang.com/errors-and-exceptions上阅读Erlang课程
我不明白这一部分:
据说try和of之间的表达受到保护.这意味着将捕获该调用中发生的任何类型的异常.
和
异常的受保护部分不能是尾递归.
[...]
通过在of和catch之间进行递归调用,您不在受保护的部分中,并且您将受益于Last Call Optimization.
所以我们不能在捕获异常的部分放置递归调用?那么try catch块有什么意义呢?
在页面下面我们有一个示例,在受保护的部分中有一个尾递归函数...
has_value(Val, Tree) ->
try has_value1(Val, Tree) of
false -> false
catch
true -> true
end.
has_value1(_, {node, 'nil'}) ->
false;
has_value1(Val, {node, {_, Val, _, _}}) ->
throw(true);
has_value1(Val, {node, {_, _, Left, Right}}) ->
has_value1(Val, Left),
has_value1(Val, Right).
Run Code Online (Sandbox Code Playgroud)
他是否意味着当我们处于try catch的受保护部分时,我们需要使用函数将尾递归代码包装到函数中?
例如,其中一个MOV有两个版本,一个带有REX,一个没有(来自英特尔的doc):
88 /r MOV r/m8, r8
REX + 88 /r MOV r/m8***, r8***
***In 64-bit mode, r/m8 can not be encoded to access the following byte registers if a REX prefix is used: AH, BH, CH, DH.
Run Code Online (Sandbox Code Playgroud)
根据我的理解,2条指令是相同的,除了第二条指令使用额外的字节并提供更少的选项......所以基本上它是无用的.
我错过了什么?
我有一个具有同级排序的树层次结构。我需要添加对其他树的引用。
这是数据:
drop table if exists org; CREATE TABLE org(id int primary key, name text, boss int, sibling int, ref int) without rowid;
INSERT INTO org VALUES(0, 'Alice', NULL, null, null);
INSERT INTO org VALUES(1, 'Bob', 0, null, null);
INSERT INTO org VALUES(2, 'Cindy', 0, 1, null);
INSERT INTO org VALUES(3, 'Dave', 1, 4, 7);
INSERT INTO org VALUES(4, 'Emma', 1, null, null);
INSERT INTO org VALUES(5, 'Fred', 2, null, null);
INSERT INTO org VALUES(6, 'Gail', 2, 5, null);
INSERT …
Run Code Online (Sandbox Code Playgroud) 我希望我的应用程序在保存文件时自动更新.所以我使用inotify(ubuntu)来创建检测事件的观察者.
问题是vim会覆盖文件而不是更新它.所以我的观察者在第一次更新后丢失了.
我想知道,有没有办法设置vim所以它不使用交换文件并直接更新文件?
(我尝试:set noswapfile
了-n
选项,删除交换文件而不改变行为)
我开始使用c ++并且已经出错...
我正在尝试编译levelDB的一个小测试:
#include <assert.h>
#include "leveldb/db.h"
using namespace std;
int main() {
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);
assert(status.ok());
return 1;
}
Run Code Online (Sandbox Code Playgroud)
这是g ++命令:
g++ -I include/ testLevelDB.cpp
Run Code Online (Sandbox Code Playgroud)
输出:
/tmp/ccuBnfE7.o: In function `main':
testLevelDB.cpp:(.text+0x14): undefined reference to `leveldb::Options::Options()'
testLevelDB.cpp:(.text+0x57): undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)'
Run Code Online (Sandbox Code Playgroud)
include文件夹是具有levelDB标头的文件夹.
互斥锁会随机成功或失败,失败时会出现以下情况:
Invalid argument
Run Code Online (Sandbox Code Playgroud)
或者
tpp.c:62: __pthread_tpp_change_priority: Assertion `new_prio == -1 || (new_prio >= __sched_fifo_min_prio && new_prio <= __sched_fifo_max_prio)' failed.
Run Code Online (Sandbox Code Playgroud)
该代码非常基本,您可以在此处看到:
pthread_mutex_t mutex;
main() {
int ret;
pthread_mutexattr_t attr;
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
ret = pthread_mutex_init(&mutex, &attr);
if (ret != 0) {
printf("pthread_mutex_init\n");
return 1;
}
ret = pthread_mutex_lock(&mutex);
if (ret != 0) {
printf("mutex_lock failed %s\n", strerror(ret));
return 1;
}
ret = pthread_mutex_unlock(&mutex);
if (ret != 0) {
printf("mutex_unlock failed %s\n", strerror(ret));
return -1;
}
Run Code Online (Sandbox Code Playgroud)
这是为什么 ?
我的意思是在不使用write()的情况下直接在内存中更新数据.
在linux中我认为在msync调用中指定的所有数据都被刷新了.
但是在Windows中,FlushViewOfFile的文档说"写脏页",所以操作系统知道哪些页面已被更新.
这是如何运作的 ?我们是否必须使用WriteFile来更新映射内存?如果我们在linux中使用write(),msync只会同步脏页吗?
在 x86_64 中,没有 64 位地址的直接跳转。只有一个 32 位的。通过间接跳转,我理解在分支预测发挥作用之前必须解决管道一次。我的问题是:在 64 位中没有办法在第一次执行时进行 1-3 个周期的跳转吗?