Corrupted NSMutableString
Corrupted NSMutableString
- Subject: Corrupted NSMutableString
- From: Matthew <email@hidden>
- Date: Mon, 28 Jul 2003 13:08:34 -0700 (PDT)
Hello!
I am a long-time programmer, but I am working on my first Cocoa
program. (I'm still using a bit of C in my Cocoa program...) Please
forgive me if this is stupid question.
I'm working on a simple program that reads in data from a binary file,
processes the information, and copies it to a plain text file (for
processing in MATLAB). I can read all of the data in fine. I can even
print it without a problem. I'm reading the data and appending it to a
NSMutableString so that I can use writeToFile to save the new text
file. For some strange reason, the NSMutableString gets corrupted. Only
the last two lines are important at the moment. The printf works fine,
but the appendFormat randomly chokes. (I've checked the values by hand
using a hex editor.)
short int * zeroCalibrations[*numOfChannels];
short int * gainCalibrations[*numOfChannels];
short int trial[*numOfChannels];
...
NSMutableString * matlabFile = [[NSMutableString alloc]
initWithString:@""];
... various loops ...
[dataFile getBytes:trial range:NSMakeRange(*headerLength + cellLength +
(q * ((*numOfChannels * 2) * *numOfSampPointsPerOb)) + (r *
(*numOfChannels * 2)), 2 * *numOfChannels)];
... more loops ...
printf("%.3f", (trial[s] - (float)*zeroCalibrations[s]) * 400 /
*gainCalibrations[s]);
[matlabFile appendFormat:@"%.3f ", (trial[s] -
(float)*zeroCalibrations[s]) * 400 / *gainCalibrations[s]];
(Please excuse the use of C type arrays, but they worked quite well for
reading a string of short integers...)
After appending the 2472143rd float (-10.342), to the end of matlabFile
the string gets erased and the 2472144th element (-17.289) becomes the
first item. If I just put a blank space after the %.3f, then the first
string that I try to write comes out ok, but the the second string gets
truncated at a different spot.
At this moment, I'm at a loss. I've stepped through the file while
checking all the variables. Everything goes fine until the string gets
erased. The string should end up being about 30MB, but gets cut down to
10.9MB. The following strings get processed without a problem. If I
make a simple change to what get appended, then the location of the
problem moves.
I know that this is probably a simple oversight on my part, but any
assistance that you could provide would be greatly appreciated.
Thank you!
-Matthew
_______________________________________________
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.