3 ms·
Java used to do something like that for strings, where taking a substring of a string created an object that pointed into the original string, but that only was
by Someone 4y ago
Java used to do something like that for strings, where taking a substring of a string created an object that pointed into the original string, but that only was for strings, and didn’t expose the pointer, so the implementation could keep a pointer to the original string around for the GC to use.
C# has Span<T>, nowadays, but is guaranteed to only live on the stack, making it easier for the GC to keep the object it points into alive while the Span lives (https://docs.microsoft.com/en-us/dotnet/api/system.span-1?view=net-6.0 https://docs.microsoft.com/en-us/dotnet/api/system.span-1?vi...)