C++ Native array ruminations

C++ native arrays. Exciting subject by no means.  Where the key and unique to C++ is the concept of the native array reference. A central concept to C++ native array handling.

If you agree with this statement, you are perhaps in one of the two opposing factions of the church of c++. Therefore, I can further deduce, you believe in A or B:

  1. Native array references are an implementation of the god’s will
  2. Special care must be taken to exorcise, all native array references

Or as a sober alternative, you refuse to take sides?  Then perhaps it might interest you, I have done and I am indeed using in my code, two different, but conceptually the same C++ utilities to easier use and manage native arrays.

The first abstraction is dbj::ARH, or Array Helper abbreviated.  The post is here. (updated)

The second utility I  am callingdbj::narf Please proceed here.

When and if there is enough time  I plan to merge them into one.

C++ Convert any character sequence to any standard string

Four standard char types can be transformed to each other
Four standard char types can be transformed to each other

(Note: this is the second part of C++ : codecvt deprecated. Panic? )

Standard C++ std lib, is one very complete and useful library. But there are times when you do realize you can build one or two of very simple utilities on top of it.

Simple but sometimes surprisingly powefull. Continue reading “C++ Convert any character sequence to any standard string”

C++ Small string optimizations

One size does not fit all
One size does not fit all

What is “small string optimization”?

Standard C++  string stores its data on the heap. But that is only true if the string  grows over an implementation-dependent size. That predefined  size for std::string is/was 15 for MSVC and GCC and 23 for Clang.  That is: C++ string stays “small”, if  you have not asked for bigger than 15/23 sized strings. The string will not attempt to grow its storage on the heap if it can stay small.

Heap memory allocations/de-allocations are taking a lot of time when compared to most standard C run time calls.

Thus if you avoid them your program will run faster and will consume less memory. Continue reading “C++ Small string optimizations”