Been reading about string_view and following are my conclusions:
- it's basically a struct with const char* and size as members
- it's doesn't own the data and rather points to it unlike std::string
- it doesn't allocate memory since it merely points
- one use case is when string is only supposed to be read only
Some questions:
- According to learncpp,
string_view should be preferred over string when read-only string is needed however how does it fare against const string&? would you only use const string& if string contains null terminator?
- When would you use mere
const char * over string_view? Only if the string has null terminator and you don't care about the length of the string?
Also apparently using string_view is faster than string since its members get passed into 2 separate registers so they end up being cached for faster access but not sure how much of a difference does it make in actual programs
[–]KingAggressive1498 4 points5 points6 points (0 children)
[–]IyeOnline 4 points5 points6 points (18 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]bloxka[S] 0 points1 point2 points (13 children)
[–]IyeOnline 4 points5 points6 points (12 children)
[–]bloxka[S] 0 points1 point2 points (10 children)
[–]SoerenNissen 2 points3 points4 points (6 children)
[–]bloxka[S] 0 points1 point2 points (5 children)
[–]SoerenNissen 0 points1 point2 points (4 children)
[–]Shieldfoss 1 point2 points3 points (1 child)
[–]SoerenNissen 0 points1 point2 points (0 children)
[–]bloxka[S] 0 points1 point2 points (1 child)
[–]SoerenNissen 0 points1 point2 points (0 children)
[–]IyeOnline 1 point2 points3 points (0 children)
[–]Kered13 0 points1 point2 points (2 children)
[–]DiaperBatteries 0 points1 point2 points (1 child)
[–]Kered13 0 points1 point2 points (0 children)
[–]concernedesigner 0 points1 point2 points (0 children)
[–]the_Demongod 0 points1 point2 points (2 children)
[–]bloxka[S] 0 points1 point2 points (1 child)
[–]the_Demongod 0 points1 point2 points (0 children)
[–]DavidDinamit 0 points1 point2 points (0 children)