Given an arbitrary floating point number, say -0.13, suppose we have an algorithm which calculates a binary string of known length L for this number, one by one, from left to right.
(I need to do this computation for calculating the Morton Key ordering for particles(co-orindates given) which in turn in used in building octrees. I am creating such binary strings for each of x,y,z dimensions)
Is it better/efficient to first create a character array of length L, and then convert this array into a string? i.e.
char ch[L]; for(i = 0; i < L; ++i) { // calculation of ch[i] } //convert array into string Or is it better/efficient to start of with a empty string, and then concatenate a new calculated bit into the string on the fly. i.e.
string s = ""; for(i = 0; i < L; ++i) { // calculation of ch[i] s = s + string(ch); }
char*. It is simply an array ofchars. If you pass that to any function expecting a null-terminatedchar*, you will get unpleasant results.