该阵营v0.12发布公告包括以下内容:
新功能:
Run Code Online (Sandbox Code Playgroud)* React.addons.batchedUpdates added to API for hooking into update cycle
但是,我找不到此API的任何文档.它的目的是什么?
具体来说,它有相同的机会Ember.run()
吗?
如果我设置buggy
为true
.
由于我对 indexedDB 还很陌生,所以我想问这是否应该起作用。如果我删除数据库并使用 再次打开它version=1
,我的回调不应该onupgradeneeded
被调用吗?
<html>
<head>
<script type="text/javascript">
var i = 1000;
var buggy = true;
function open() {
var version = buggy ? 1 : 1001 - i;
var request = indexedDB.open("test", version);
var upgraded = false;
request.onupgradeneeded = function() {
upgraded = true;
console.log("upgraded ok");
}
request.onsuccess = function() {
if (!upgraded) {
throw "Not upgraded";
}
console.log("open ok");
if (--i != 0) { obliterate(); }
}
request.onerror = …
Run Code Online (Sandbox Code Playgroud) 我有一个C库,其类型如下:
typedef struct {
// ...
} mytype;
mytype *mytype_new() {
mytype *t = malloc(sizeof(*t));
// [Initialize t]
return t;
}
void mytype_dosomething(mytype *t, int arg);
Run Code Online (Sandbox Code Playgroud)
我想提供C++包装器来提供更好的语法.但是,我想避免使用单独分配的包装器对象的复杂性.我有一个相对复杂的对象图,其内存管理已经比我想要的更复杂(对象以所有可到达对象保持活动的方式被重新计算).此外,C库将使用指向此对象的指针回调到C++,并且为每个C-> C++回调构建一个新的包装器对象的成本(因为C不知道包装器)对我来说是不可接受的.
我的一般计划是:
class MyType : public mytype {
public:
static MyType* New() { return (MyType*)mytype_new(); }
void DoSomething(int arg) { mytype_dosomething(this, arg); }
};
Run Code Online (Sandbox Code Playgroud)
这将为C++程序员提供更好的语法:
// C Usage:
mytype *t = mytype_new();
mytype_dosomething(t, arg);
// C++ Usage:
MyType *t = MyType::New();
t->DoSomething(arg);
Run Code Online (Sandbox Code Playgroud)
我正在向a 铸造一个mytype*
(分配给它malloc()
)MyType*
,这是谎言.但是如果MyType
没有成员而没有虚函数,似乎我应该能够依赖sizeof(mytype) …
我可以假设以下不变量吗?
void foo(char *buf, size_t len) {
// "buf" points to either an array or memory allocated with malloc().
assert((uintptr_t)(buf + len) < UINTPTR_MAX);
}
Run Code Online (Sandbox Code Playgroud)
在我正在编写的解析器中,我想使用指针标记某些偏移:例如,我可能有char *end_of_submessage
,end_of_submessage
相对于我当前的缓冲区.但是如果子消息没有在当前缓冲区内结束,我想使用一个大于当前缓冲区中任何偏移量的值.所以我会这样做:
void parse(char *buf, size_t len, uintptr_t end_of_submessage) {
// Some parsing that might increment "buf"
// ...
// If end_of_submessage == UINTPTR_MAX, processing will not be
// triggered even if we have processed our entire current buffer.
if ((uintptr_t)buf >= end_of_submessage)
process_submsg_end();
}
Run Code Online (Sandbox Code Playgroud)
但是如果malloc()返回内存ptr + len == UINTPTR_MAX …