FROM : Derrek Leute
DATE : Sun Feb 17 19:40:25 2008
This is excellent to know. What about performance? Performance is
*very* important in this case. A 1% increase can knock hours or days
off of processing time on this size data set. Any performance metrics
available?
--Derrek
On Feb 17, 2008 11:54 AM, glenn andreas <<email_removed>> wrote:
>
> On Feb 17, 2008, at 10:43 AM, Derrek Leute wrote:
> > The project actually started in cocoa but I moved to CF because
> > NSDictionary forces a string copy for keys. This made memory needs go
> > through the roof (unless I'm misusing or misunderstanding how to use
> > it). CF lets me use anything as a key.
>
> Close but not quite exactly correct.
>
> NSDictionary requires that keys conform to the NSCopying protocol
> because it make a copy of the key (regardless of if it is an NSString,
> or whatever). The important part is that for a non-immutable
> NSString, it will simply increase the reference count - no increase in
> the memory usage at all. If you pass an NSMutableString as a key, it
> will make a (immutable) copy that does, in fact, increase memory usage.
>
> You may wonder why it does this - consider this:
>
> NSMutableString *s1 = [NSMutableString stringWithString: @"abc"];
> NSMutableString *s2 = [NSMutableString stringWithString: @"def"];
> NSMutableDictionary *d = [NSMutableDictionary dictionary];
>
> [d setObject; [NSNumber numberWithInt: 1] forKey: s1];
> [d setObject: [NSNumber numberWithInt: 2] forKey: s2];
> [s1 setString: @"def"];
>
> NSLog(@"%@", [d objectForKey: @"def"]);
>
> If it didn't make an immutable copy, you would end up with two values
> that both have the key "def".
>
> So, if you use immutable objects as keys, your memory usage won't go
> up. If you use mutable objects as keys, it will make a copy because
> if it didn't, bad things would happen.
>
>
> Glenn Andreas <email_removed>
> <http://www.gandreas.com/> wicked fun!
> quadrium | prime : build, mutate, evolve, animate : the next
> generation of fractal art
>
>
>
>
DATE : Sun Feb 17 19:40:25 2008
This is excellent to know. What about performance? Performance is
*very* important in this case. A 1% increase can knock hours or days
off of processing time on this size data set. Any performance metrics
available?
--Derrek
On Feb 17, 2008 11:54 AM, glenn andreas <<email_removed>> wrote:
>
> On Feb 17, 2008, at 10:43 AM, Derrek Leute wrote:
> > The project actually started in cocoa but I moved to CF because
> > NSDictionary forces a string copy for keys. This made memory needs go
> > through the roof (unless I'm misusing or misunderstanding how to use
> > it). CF lets me use anything as a key.
>
> Close but not quite exactly correct.
>
> NSDictionary requires that keys conform to the NSCopying protocol
> because it make a copy of the key (regardless of if it is an NSString,
> or whatever). The important part is that for a non-immutable
> NSString, it will simply increase the reference count - no increase in
> the memory usage at all. If you pass an NSMutableString as a key, it
> will make a (immutable) copy that does, in fact, increase memory usage.
>
> You may wonder why it does this - consider this:
>
> NSMutableString *s1 = [NSMutableString stringWithString: @"abc"];
> NSMutableString *s2 = [NSMutableString stringWithString: @"def"];
> NSMutableDictionary *d = [NSMutableDictionary dictionary];
>
> [d setObject; [NSNumber numberWithInt: 1] forKey: s1];
> [d setObject: [NSNumber numberWithInt: 2] forKey: s2];
> [s1 setString: @"def"];
>
> NSLog(@"%@", [d objectForKey: @"def"]);
>
> If it didn't make an immutable copy, you would end up with two values
> that both have the key "def".
>
> So, if you use immutable objects as keys, your memory usage won't go
> up. If you use mutable objects as keys, it will make a copy because
> if it didn't, bad things would happen.
>
>
> Glenn Andreas <email_removed>
> <http://www.gandreas.com/> wicked fun!
> quadrium | prime : build, mutate, evolve, animate : the next
> generation of fractal art
>
>
>
>
| Related mails | Author | Date |
|---|---|---|
| Derrek Leute | Feb 17, 16:51 | |
| Michael Ash | Feb 17, 17:07 | |
| Derrek Leute | Feb 17, 17:43 | |
| glenn andreas | Feb 17, 17:54 | |
| Michael Ash | Feb 17, 17:59 | |
| William Squires | Feb 17, 18:07 | |
| Derrek Leute | Feb 17, 19:33 | |
| Derrek Leute | Feb 17, 19:40 | |
| Quincey Morris | Feb 17, 21:05 | |
| Derrek Leute | Feb 17, 22:00 |






Cocoa mail archive

