Showing posts with label cpp_std_string. Show all posts
Showing posts with label cpp_std_string. Show all posts

Mar 3, 2022

[POSIX][C][C++] snprintf / sprintf can be thread safe thus slow

Reference:
https://aras-p.info/blog/2022/02/25/Curious-lack-of-sprintf-scaling
https://developer.arm.com/documentation/dui0492/i/the-c-and-c---libraries/thread-safe-c-library-functions
https://twitter.com/aras_p/status/1496489672373063682

snprintf / sprintf use global locale; which the function itself is thread-safe; thus slow and not scale(contains mutex)

take away:

  1. for converting int to string, use std::to_chars instead of snprintf
  2. {fmt} comes to the rescue (increase compile time)
  3. For using Double-checked_locking, be ware: use atomic with memory model, don't use simple bool/int to make it cross platform.
  4. don't use iostream for high-performance code
  5. always profiling.

Nov 28, 2018

[C++][cppcon 2018] std::basic_string: for more than just text - Brian Ruth


This could be one of the most interesting/hacking videos in cppcon 2018 :-D

std::basic_string can be the container other then 'char'-ish type.
i.e int, bool, UDT etc.

And, it applies SSO on those types as well, thus we might ask, why vector
doesn't have SSO?
Well, we do have in LLVM:
SmallVector.h
or Boost's:
small_vector

And we might have 'relocatable' in C++20 iff vector contains type that meets Rule Of Zero.