bjacob wrote:

@jrtc27 
> const char[] allocates storage for the string contents though, so takes up 
> space in memory if the string can be merged with others at compile or link 
> time. There are multiple things being traded off here, and PDE vs PIC/PIE 
> complicates the story further. So it's not just as simple as "use const 
> char[] whenever you can".

Ah, thanks for the explanation... I really hadn't thought of that, but IIUC 
you're saying that the indirection (referring to a string via a pointer to it) 
allows merging storage when a string literal is a substring of another, while 
using raw `const char[]` doesn't allow any reuse unless the string literal 
exactly match.

Really interesting, but I still wonder -- this sounds like a fancier kind of 
optimization that probably won't be able to apply in a majority of cases (it 
needs literals to be substrings of each other?) while the relocations are every 
single time.

https://github.com/llvm/llvm-project/pull/122366
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to