Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why Substring cannot make a reference to the original data instead of a copy? #181

Open
jjxtra opened this issue Jan 25, 2023 · 1 comment

Comments

@jjxtra
Copy link

jjxtra commented Jan 25, 2023

unsafe string InternalSubString(int startIndex, int length) {

Why can't Substring just have a reference to the original unmanaged memory? Is there something with GC that would prevent a string referencing another string?

@svick
Copy link

svick commented Jan 25, 2023

This repo is not very active, so it's not a great place to ask questions like this. A better choice would be the repo for the modern .Net runtime: dotnet/runtime.

That being said, what you're saying would require changing the structure of the string type, which is a pretty fundamental part of the runtime. Instead, .Net decided to add the Span<T> type, which can represent any memory sequence, which means the equivalent operation to Substring, called Slice, works exactly the way you want there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants