Invalid Memory Allocation

瀏覽次數:22 次
跳到第一則未讀訊息

Cesar Valdez

未讀,
2016年5月26日 上午11:25:402016/5/26
收件者:v8-users
Hi All,

I working in a add-on for Node.js, and i have the following problem:

class A {

 
local<object> CreateObject( callback) {
   
     
if(!p->isEmpty()){
     
auto tmp = Object::New(Isolate, objTemplate); //get from cache.
     
return tmp->newInstance();  //we have a template, create a instance.
     
}
   
     
/* create object here and assign callback  {x:callback[function]}  */
     
objTemplate.Reset(Isolate, obj);  //cache here.
     
return obj->newInstance();.
   
}

 
~A(){
   
objTemplate.Reset();  
 
}

 
private:
 
Persistent<ObjectTemplate> objTemplate;
}

/* NativeFunction declared here will be linked to obj methods created by A */

A a
;
void MakeObject(functionCallbackInfo args){
   args
->GetReturn().Set(a.CreateObject(NativeFunction))

}







Javascript
Enter code here...
(function(){

  for(var i=0; i<1000; i++) {
  
   // this call MakeObject in C++.
   var tmp = make_object();            // tmp => {n:[function],....};
  }

})





I just want to cache the Object members using a template, cause i find that it was way slower to make the object from scratch, problem is that when the VM finish i got a SIGSEGV Segmentation fault,
I'm assume this is because of GC, so I add the cleaning function in the desctructor but not luck, the only way to avoid the SIGSEGV is to delete the object way before exit.

I'm thinking to use Eternal<>, but just wanted to know if this is not a good use case for Persistent?  Is a more elegant way to solve this problem ? or I'm doing something wrong.

Thanks. 
 








joko suwito

未讀,
2016年5月27日 凌晨2:43:132016/5/27
收件者:v8-u...@googlegroups.com

Thank you

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
回覆所有人
回覆作者
轉寄
0 則新訊息