I have this code:
v8::Handle<v8::Value> StartMethod(const v8::Arguments &args) {
v8::HandleScope scope; // node_isolate
int length = args.Length();
std::vector<std::unique_ptr<char[]>> argv;
for(int i=0;i<length;++i) {
if(args[i]->IsString()) {
v8::String::Utf8Value str(args[i]);
const int strLen = ToCStringLen(str);
if(strLen) {
std::unique_ptr<char []> data(new char[strLen+1]);
strcpy_s(data.get(), strLen+1, ToCString(str));
argv.push_back(std::move(data));
}
}
}
return scope.Close(v8::Int32::New(MainMethod(argv.size(), &(argv[0]._Myptr))));
}
I am using std::move and it is working fine.
When i do not use std::move it gives me compiler errors because of unavailability of assignment function.
But Does it guarantees that when vector changes its location, may be because of some internal re sizing and move objects around, nothing bad would happen ?
&(argv[0]._Myptr)in the last line of this? Accessing that pointer through this mechanism is bad enough, I don't even want to guess why you're passing the address of it to... something. You would be hard-pressed to find something less portable or standard.char **at that location. Can you suggest a better method there.char *tmp = data.get();, and use&tmpI assume this is astrtol-type function, and if so, and it returns termination info in the resulting pointer-to-pointer (i.e. it modified the pointer) the behavior is beyond undefined. Even accessing that member is implementaiton-specific, Use a temp ptr anyway. What you're doing now with&(argv[0]._Myptr)is dreadful.