c++ - How to return a pointer char from v8 to javascript -
i return char pointer v8 javascript, not work. in js length of result not good. example outlength 43529bytes in v8, in js have 4 bytes. correct in using return string::new((char *)img);
javascript:
var result = module.encode(); console.log(result.length);
v8
handle<value> encode(const arguments& args) { file *pinputfile = fopen ( "images/file.rgb" , "rb" ); if (!pinputfile ) { fprintf(stderr, "could not open %s\n", "vr.rgb"); exit(1); } fseek (pinputfile , 0 , seek_end); long lsizeinput = ftell (pinputfile ); rewind (pinputfile ); char *img=(char*) malloc(lsizeinput*sizeof( char )); fread (img,1,lsizeinput,pinputfile); cout<<"length = "<< lsizeinput<<endl; return string::new((char *)img); }
Comments
Post a Comment