For version 0.2.0 of DTMarkdownParser I needed an array that would allow me to look up the string range for individual lines of a string. My initial approach was to simple use the provided method of NSValue to wrap an NSRange in it. The problem with this approach is that as the number of ranges in the array grows so does the time needed to find a range at a higher index.
Jan Weiß of Geheimwerk suggested to replace this approach with one based on C memory allocation and searching functions. This required me to brush up on my dynamic C-array allocation skills which had become somewhat rusty from only using Objective-C objects for everything. The techniques I’ll be discussing in this blog might be of great value to you, too, if you ever find yourself needing to quickly find a scalar value (i.e. a number or struct) in a dynamically sizing array.