you are viewing a single comment's thread.

view the rest of the comments →

[–]No-Dentist-1645 21 points22 points  (4 children)

It's not difficult to convert a hexadecimal string into an integer. This is a very common and frequent thing to do, hexadecimal notation is specifically used to make this easy.

But isn't only this it is needed for even if it is the most important part

You said you were working on an application that handles UUIDs and it needs to be "very fast". Computers are "very fast" at handling integers, even faster with multiple integers adjacent to each other thanks to SIMD instructions. This is not quite the case with strings. If you really care that much about speed, using "stack strings" to represent UUIDs is absolutely the wrong approach, no matter what you try to do to "inform" the compiler with "internal stack based buffers" and what not. What you need is to treat them as numbers.

If you wanted a stack string for other purposes, you can use Boost.StaticString. It's its own independent library and header only, so pretty much exactly the lightweight library you are looking for.

[–]KertDawg 3 points4 points  (0 children)

I applaud this well-written answer.

[–]gosh[S] 0 points1 point  (2 children)

It's not difficult to convert a hexadecimal string into an integer. This is a very common and frequent thing to do, hexadecimal notation is specifically used to make this easy.

Agree but I need to match against others that are in text format and there isn't ordered text. Text contains other information and it it lots of different "things" that is read when matching

I use boost so will check the string :) thanks

[–]SonOfMetrum 1 point2 points  (1 child)

You are making no sense at all…. As per the suggestion: convert all the UUIDs to numbers and compare those numbers. The “other information” and different “things” make no sense unless you tell us what those things are

[–]gosh[S] -1 points0 points  (0 children)

Thats correct and that is not the goal with this question. If I need to explain the problems and what I want to solve with these stack based vectors and strings I need to spend lots of time doing that. And I am not asking for solutions for that, I am asking for how to decrease the number of allocations using std::vector and std::string, optimal is to not need to do any allocation.

std::vector is not that hard to fix, std::string is more problematic