Re:C Strings and my slow descent to madness
by saagarjha on Thursday April 06, 2023 @09:31PM
(#35476960)
What’s the ownership story for string views?
[ Parent
| on HN ]
They don't own anything. It's just a pointer and length. They don't allocate/deallocate.
Re:C Strings and my slow descent to madness
by saagarjha on Friday April 07, 2023 @03:46AM
(#35479218)
I mean clearly something needs to own the buffer for a new string.
Re:C Strings and my slow descent to madness
by tialaramex on Monday April 17, 2023 @06:08AM
(#35598772)
Sure, but that's not the string_view's problem, you can't just make string_views, the string you want to borrow a view into needs to exist first.
Imagine you go to a library and insist on borrowing "My Cousin Rachel", but they don't have it. "Oh I don't care whether you have the book, I just want to borrow it" is clearly nonsense. If they don't have it, you can't borrow it.
Re:C Strings and my slow descent to madness
by saagarjha on Thursday April 20, 2023 @05:07AM
(#35637794)
Walter is talking about D, and he said this:
> D doesn't distinguish between a string and a string view.
In C++ std::string owns the buffer and std::string_view borrows it. If there is no difference between the two in D, then how is this difference bridged?
Re:C Strings and my slow descent to madness
by WalterBright on Friday April 07, 2023 @12:32AM
(#35478054)
You can use automatic memory management and not worry about it. Or you can use D's prototype ownership/borrowing system. Or you can encapsulate them in something that manages the memory. Or you can do ownership/borrowing by convention (it's not hard to do).
Re:C Strings and my slow descent to madness
by saagarjha on Friday April 07, 2023 @03:46AM
(#35479223)
Automatic memory management makes copies?
Re:C Strings and my slow descent to madness
by WalterBright on Friday April 07, 2023 @09:08AM
(#35481193)
No. Another word for automatic memory management is garbage collection.