currently following:
// float *c_array = new float[1024]; void foo::foo(float *c_array, size_t c_array_size) { //std::vector<float> cpp_array; cpp_array.assign(c_array, c_array + c_array_size); delete [] c_array; }
how can optimize assigning? not perform elementwise copy swap pointers.
the current std::vector
doesn't provide capability or interface take ownership of allocated storage. presumably easy pass stack address in accident, allowing more problems solved.
if want avoid copying vector, you'll either need use vectors through entire call chain, or c way float[]
entire time. can't mix them. can guaranteed &vec[0]
equivalent c-array though, contiguous, using vector in whole program may feasible.
Comments
Post a Comment