In a C++ program, where is constant data stored, especially string constants ?
I am asking because in the following question:
Why can creating a static const std::string cause an exception?
The answer by Damon, has the following at the end:
A string_view will, contrary to a string, not allocate non-constant memory, copy constant data into that, and then pretend it's constant. Instead, it will manage a pointer directly to the constant data, and that's all.
That way, your constants are truly (not just formally) constant, there are no allocations, no possibility of exceptions, and no double memory usage. And for the most part, it still looks and smells like a string. The only notable differences being that a string_view doesn't guarantee nul-termination (but the character constant it points to does, so this is irrelevant), and the fact that it's really constant, not modifiable... which is exactly what you want.
Dont even the constants need to be stored in memory some where ? And if they are stored in memory (since memory is finite), isn't it possible an exception can be thrown because there is no more memory ?