[Biococoa-dev] Caching the NSArray of BCSymbol
Charles Parnot
charles.parnot at gmail.com
Wed Jul 6 13:44:14 EDT 2005
On Jul 6, 2005, at 5:25 AM, John Timmer wrote:
>> I'm wondering to what extend we really need to cache the array of
>> symbols, in fact when does one really need that array at all? Only
>> if you ask a single position you get the symbol, in all other
>> instances you don't want an array of symbols right, you want a
>> BCSequence. So a subsequence -> a bcsequence is returned (again
>> containing the char[]), the reverse of a BCSequence -> a
>> bcsequence is returned etc... Want to display a sequence in a view
>> -> the stringrepresentation of the bcsequence object is given.
>> When would you like an array of symbols?
>> Alex
>>
> The symbols are the things that actually convey information. Say
> you want to generate all the information and statistics about a
> sequence (complement, reverse complement, MW, melting point, etc.)
> for display. Without a cached version, the sequence array would
> have to be recreated from data several times – doing so would
> probably be the single largest time cost before the info could be
> displayed.
>
> JT
Then, we should only cache it in one place: the accessor. Though for
mutable sequences, we also need to remember to set the cached array
to nil after modifications. Something like this:
- (NSArray *)symbolArray
{
if ( cachedArray == nil ) {
cachedArray = ... //generate the array (and retain it)
}
return cachedArray;
}
- (void)emptyCache
{
[cachedArray release];
cachedArray = nil;
}
- (void)appendSequence:(BCSequence *)otherSequence
{
//code to append the sequence
...
//empty the cache: the array is not valid anymore!!
[self emptyCache];
}
what do you think?
charles
--
Xgrid-at-Stanford
Help science move fast forward:
http://cmgm.stanford.edu/~cparnot/xgrid-stanford
Charles Parnot
charles.parnot at gmail.com
More information about the Biococoa-dev
mailing list