• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSMutableString & re-initing...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSMutableString & re-initing...


  • Subject: NSMutableString & re-initing...
  • From: Jeff Knee <email@hidden>
  • Date: Wed, 13 Nov 2002 18:42:45 -0500

All,

Here is some code that I've hopefully trimmed down and still left readable that I was trying to speed up a little bit.

NSFileHandle *wordFile = [NSFileHandle fileHandleForReadingAtPath:@"./some.txt"];
NSMutableString *wordString = [NSMutableString alloc];
int readLength = 8192;

NSData *wordData = [wordFile readDataOfLength:readLength];
while (0 != [wordData length])
{
wordString = [[NSMutableString alloc] initWithData:wordData
encoding:NSASCIIStringEncoding];

// [snipped out other stuff]

wordData = [wordFile readDataOfLength:readLength];
}

I was pulling other object allocations to outside the loop and things were getting faster. I wanted to pull the [NSMutable alloc] out of the loop also. So, I'd have:

wordString = [wordString initWithData:wordData
encoding:NSASCIIStringEncoding];

But, I found that on the second pass of the loop I'd get a run time error (SIGTRAP) if I did so.

Is the problem that NSMutableString can't be "re-inited"? Is there something I could do to the NSMutableString so that it would be 'happy' being "re-inited"?

Is there another way to get the NSData into a NSMutableString that I'm not catching?

Or, is "receiver = [receiver selector];" not a valid idiom for some reason? (I've rewritten objects that allow themselves to be re-inited but in the cases I've done this I've used [self init:blah] type of code.)

Thanks!

+= Jeff Knee
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: ABAddressBook anomaly.
  • Next by Date: Re: Thread question
  • Previous by thread: Re: ABAddressBook anomaly.
  • Next by thread: Scrollbar
  • Index(es):
    • Date
    • Thread