[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSMutableString -initWithFormat appends to existing text
From: |
David Chisnall |
Subject: |
Re: NSMutableString -initWithFormat appends to existing text |
Date: |
Wed, 18 Apr 2018 16:15:02 +0100 |
On 18 Apr 2018, at 10:23, Mick Bert <micbert75@gmail.com> wrote:
>
> One question more. I am writing in a text file, by formatting NSString
> objects to give to NSFileHandle -writeData.
That’s a sensible thing to do. The reason for going via NSData is that
NSString itself is representation agnostic. When you generate an NSData, you
are explicitly telling the string how to encode the characters and transforming
it into a concrete representation (which may or may not be the same encoding as
the in-memory representation used by the NSString class).
> Is it the preferable way?
That depends a bit on what you mean by ‘preferable’. If you mean ‘simpler’ or
‘cleaner code’, then I don’t think so. If you mean ‘faster’ or ‘lower memory’,
then you may find that using NSString’s -getBytes:… method (I forget exactly
which one GNUstep provides - I need to add the version Apple now provides) into
an on-stack buffer then write that using the lower-level C / C++ APIs. In most
cases, the overhead of the I/O is going to be sufficient that this won’t make a
noticeable difference, but if you’re processing a lot of data and have NVMe
storage then you might consider this.
> Are there any other class to work with
> text-oriended files?
Note that text-oriented files don’t really exist as an abstraction on most *NIX
systems (though the C standard still likes to pretend that they do). GNUstep /
Cocoa don’t provide useful abstractions for this, though the C++ standard
streams library does (not very good ones though, so I don’t really suggest
using it).
David
- NSMutableString -initWithFormat appends to existing text, Mick Bert, 2018/04/18
- Re: NSMutableString -initWithFormat appends to existing text, H. Nikolaus Schaller, 2018/04/18
- Re: NSMutableString -initWithFormat appends to existing text, Mick Bert, 2018/04/18
- Re: NSMutableString -initWithFormat appends to existing text, Ivan Vučica, 2018/04/18
- Re: NSMutableString -initWithFormat appends to existing text, Mick Bert, 2018/04/18
- Re: NSMutableString -initWithFormat appends to existing text, Riccardo Mottola, 2018/04/18
- Re: NSMutableString -initWithFormat appends to existing text, Mick Bert, 2018/04/18
- Re: NSMutableString -initWithFormat appends to existing text, Riccardo Mottola, 2018/04/18
- Re: NSMutableString -initWithFormat appends to existing text, David Chisnall, 2018/04/18
- Re: NSMutableString -initWithFormat appends to existing text,
David Chisnall <=
- Re: NSMutableString -initWithFormat appends to existing text, Mick Bert, 2018/04/19
- Re: NSMutableString -initWithFormat appends to existing text, David Chisnall, 2018/04/19
Re: NSMutableString -initWithFormat appends to existing text, David Chisnall, 2018/04/18