Is there a function in the IOS Api that is like substringFromIndex excepts uses a lot less memory (I am using VERY VERY large strings). If I would have to make that function how would I go about doing that?
Thanks in advance
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, but it’s kind of roundabout and potentially dangerous
Here’s what you do:
What is this doing:
NSDatato begin with instead of anNSString, then you can be much more confident that nothing’s going to get copied.NSDataNSStringwith the byte buffer, but telling it to NOT copy the bytes, and to NOT free the buffer when theNSStringis deallocatedSo, why is this dangerous? Basically, if the byte buffer disappears from underneath the
NSStrings, Bad Things™ can happen (likely crashing).However, if you’re smart about it, this will allow you to create substrings without copying the underlying bytes.
Devious thought:
You could make
veryLargeStringa retained associated object onsubstring(i.e., basically makesubstringan owner ofveryLargeString). This would ensure thatveryLargeStringlives at least as long assubstringdoes. You’d do that like this:When
substringis deallocated, it’ll also automatically release its retain onveryLargeString.