With the NSGlyph glyphs[5000]
notation, you're allocating the memory on the stack. But instead of 5000 glyphs it only has to hold visibleRange.length + 1
glyphs:
glyphArray
On output, the displayable glyphs from glyphRange, null-terminated. Does not include in the result any
NSNullGlyph
or other glyphs that are not shown. The memory passed in should be large enough for at leastglyphRange.length+1
elements.
And because it is on the stack, you don't have to worry about freeing the memory—because never malloced memory; it is freed automatically when leaving the function—even without ARC
So it should work, if you write it like this:
NSLayoutManager *lm = ...
NSRange glyphRange = ...
NSGlyph glyphArray[glyphRange.length + 1];
NSUInteger numberOfGlyphs = [lm getGlyphs:glyphArray range:glyphRange];
// do something with your glyphs