[Question] 为什么SetPointer需要把指针拆成高4位和低4位 #1558
Answered
by
chexiongsheng
BlurryLight
asked this question in
Q&A
-
//替代 Object->SetAlignedPointerInInternalField(Index, Ptr);
FORCEINLINE static void SetPointer(v8::Isolate* Isolate, v8::Local<v8::Object> Object, const void* Ptr, int Index)
{
// Object->SetInternalField(Index, v8::External::New(Isolate, Ptr));
// Object->SetAlignedPointerInInternalField(Index, Ptr);
UPTRINT High;
UPTRINT Low;
SplitAddressToHighPartOfTwo(Ptr, High, Low);
Object->SetAlignedPointerInInternalField(Index * 2, reinterpret_cast<void*>(High));
Object->SetAlignedPointerInInternalField(Index * 2 + 1, reinterpret_cast<void*>(Low));
} 比如参考下 https://github.com/pmed/v8pp/blob/fa7f72afba0674322d0448fb55a28fd16caa1958/v8pp/class.ipp#L207 if (class_function_template()->GetFunction(context).ToLocal(&func)
&& func->NewInstance(context).ToLocal(&obj))
{
obj->SetAlignedPointerInInternalField(0, Traits::pointer_id(object));
obj->SetAlignedPointerInInternalField(1, this);
|
Beta Was this translation helpful? Give feedback.
Answered by
chexiongsheng
Oct 17, 2023
Replies: 1 comment
-
AlignedPointer要求字节对齐,低一位还是两位必须为0。 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
BlurryLight
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AlignedPointer要求字节对齐,低一位还是两位必须为0。
class/struct是可以设置0字节对齐的,它的field的地址可能不字节对齐。
不知道为啥v8pp发布那么久连这点都没遇到过?而且我拆了性能还远比它高:https://zhuanlan.zhihu.com/p/649362608