Korzystanie z NSGlyph i przydzielanie pamięci
w metodzie śledzenia przerw liniiczęsto, dlaNSTextView visibleRect
, alokuję pamięć dlaNSGlyph używaćNSLayoutManager getGlyphs:range:
.
powinienem / powinienem dowiedzieć się, ile pamięci powinno być, ponieważ mam odnośnik do zakresu (bez wpływu na układ), a także, jaki rodzaj czyszczenia powinien się odbywać - działający zŁUK ?
kod (który działa w głównej kolejce):
NSLayoutManager *lm = [self.textView layoutManager];
NSTextContainer *tc = [self.textView textContainer];
NSRect vRect = [self.textView visibleRect];
NSRange visibleRange = [lm glyphRangeForBoundingRectWithoutAdditionalLayout:vRect inTextContainer:tc];
NSUInteger vRangeLoc = visibleRange.location;
NSUInteger numberOfLines;
NSUInteger index;
NSGlyph glyphArray[5000]; // <--- memory assigned here
NSUInteger numberOfGlyphs = [lm getGlyphs:glyphArray range:visibleRange];
NSRange lineRange;
NSMutableIndexSet *idxset = [NSMutableIndexSet indexSet];
for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++) {
(void)[lm lineFragmentRectForGlyphAtIndex:index effectiveRange:&lineRange withoutAdditionalLayout:YES];
[idxset addIndex:lineRange.location + vRangeLoc];
index = NSMaxRange(lineRange);
}
self.currentLinesIndexSet = idxset;