Alright.. firstly I needed something that did what this question is asking, but I needed it FAST! Unfortunately the "better" way is nearly 600 lines of code!!! Pardon the name of it that doesn't have anything to do with what it's doing. Proper name was Integer64ToCharArray(int64_t value);
https://github.com/JeremyDX/All-Language-Testing-Code/blob/master/C%2B%2B%20Examples/IntegerToCharArrayTesting.cpp
Feel free to try cleaning that code up without hindering performance.
Input: Any signed 64 bit value from min to max range.
Example:
std::cout << "Test: " << AddDynamicallyToBuffer(LLONG_MAX) << '\n';
std::cout << "Test: " << AddDynamicallyToBuffer(LLONG_MIN) << '\n';
Output:
Test: 9223372036854775807
Test: -9223372036854775808
Original Speed Tests: (Integer64ToCharArray();)
Best case 1 digit value.
Loops: 100,000,000, Time Spent: 1,381(Milli), Time Per Loop 13(Nano)
Worse Case 20 Digit Value.
Loops: 100,000,000, Time Spent: 22,656(Milli), Time Per Loop 226(Nano
New Design Speed Tests: (AddDynamicallyToBuffer();)
Best case 1 digit value.
Loops: 100,000,000, Time Spent: 427(Milli), Time Per Loop 4(Nano)
32 Bit Worst Case - 11 digit Value.
Loops: 100,000,000, Time Spent: 1,991(Milli), Time Per Loop 19(Nano)
Negative 1 Trillion Worst Case - 14 digit Value.
Loops: 100,000,000, Time Spent: 5,681(Milli), Time Per Loop 56(Nano)
64 Bit Worse Case - 20 Digit Value.
Loops: 100,000,000, Time Spent: 13,148(Milli), Time Per Loop 131(Nano)
How It Works!
We Perform a Divide and Conquer technique and once we now the maximum length of the string we simply set each character value individually. As shown in above speed tests the larger lengths get big performance penalties, but it's still far faster then the original loop method and no code has actually changed between the two methods other then looping is no longer in use.
In my usage hence the name I return the offset instead and I don't edit a buffer of char arrays rather I begin updating vertex data and the function has an additional parameter for offset so it's not initialized to -1.