• 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
Fastest way to push strings to the screen in an NSView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fastest way to push strings to the screen in an NSView?


  • Subject: Fastest way to push strings to the screen in an NSView?
  • From: Scott Ellsworth <email@hidden>
  • Date: Wed, 17 Nov 2004 18:08:10 -0800

Hi, all.

Roughly half the time my program takes is spent drawing attributed strings to the screen, according to Shark. This surprises me, as there are no more than 1200 on the screen at once, though they are drawn at a variety of locations. The attributes are not complicated, either.

I build my attribute dict only once in the program execution with:

hexFontSize=12.0f;
attributesForRegion = [NSDictionary dictionaryWithObjectsAndKeys:
	[NSFont userFontOfSize:hexFontSize],
	NSFontAttributeName,
	nil];

Then I call the following method about 1.2k times, interleaved with pushing a few graphics to the screen as well:

- (void) drawString:(NSString *)string inRegion:(Region) theRegion{
if (string != nil){
NSDictionary * attributesForRegion=[self attributesForRegion:theRegion];
NSAttributedString * attributedString=[[NSAttributedString alloc] initWithString:string attributes:attributesForRegion];
NSSize size=[attributedString size];
NSPoint basePoint = [self pointForRegion:theRegion];
NSRect r=NSMakeRect(basePoint.x-size.width/2, basePoint.y, size.width, size.height);
[attributedString drawInRect: r];
[attributedString release];
}
}


attributesForRegion always returns the above dictionary of attributes, and pointForRegion is a fast integer calculation.

drawAtPoint:withAttributes: seemed about the same speed, and adds the complexity of trying to justify the result.

This is on Panther 10.3.6, running on my AlBook/1.5GHz.

NB - documentation refs, google URLs, and other pointers to info are fine - I tried a number of searches first, but did not find anything obvious.

Scott

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Fastest way to push strings to the screen in an NSView?
      • From: "M. Uli Kusterer" <email@hidden>
    • Re: Fastest way to push strings to the screen in an NSView?
      • From: Ricky Sharp <email@hidden>
    • Re: Fastest way to push strings to the screen in an NSView?
      • From: Robbie Haertel <email@hidden>
  • Prev by Date: RE: how to make a finder-like button
  • Next by Date: Re: Fastest way to push strings to the screen in an NSView?
  • Previous by thread: Re: Suggestions for App design
  • Next by thread: Re: Fastest way to push strings to the screen in an NSView?
  • Index(es):
    • Date
    • Thread