On 10/28/05 5:03 PM, Lawrence Sanbourne didst favor us with:
>> Since FSRefs are not a CFType, have you tried this with something other than
>> a CFArray? FWIW, a simple non-CF array would be more efficient (less memory
>> and faster access) for working with FSRefs. I use the STL's vector for this,
>> but any contiguous block of memory would do.
>
> I'd like to avoid C++
Why?
>, so unfortunately the STL is out. I considered
> a simple C array, but decided that the pain of reallocating memory as
> it grows wouldn't be worth my trouble (or the computer's). Would you
> agree?
No. You're going to have to allocate memory somehow as you add more items to
the array anyway.
> Do you think it's worth it to make my own simple linked list
> struct?
I wouldn't, not if I wanted the advantages of an array. A linked list is a
very different beast and is best for different operations than those at
which an array excels. Before I used vectors, I used handles. I defined:
typedef FSRefPtr *FSRefHandle;
I then had some simple functions to work with them such as:
inline
FSRefHandle NewFSRefHandle( SInt32 inCount = 0 )
{
return ( FSRefHandle ) NewHandle( inCount * sizeof( FSRef ) );
}
inline
OSErr AppendFSRef( const FSRef& inFSRef, const FSRefHandle ioFSRefs )
{
return PtrAndHand( &inFSRef, ( Handle ) ioFSRefs, sizeof( FSRef ) );
}
inline
SInt32 Count( FSRefHandle inFSRefs )
{
return ( inFSRefs == nil ? 0 : GetHandleSize( (Handle) inFSRefs ) /
sizeof( FSRef ) );
}
You get the advantages of contiguous memory, the easy of use of vectors, and
it doesn't use anything but the Memory Manager. FWIW, I still use these a
lot because it just isn't worth the trouble to rewrite all the code I have
that uses them. I use vectors for new code and FSRefHandles when I need to
interface with existing code that can't be converted easily.
Larry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden
This email sent to email@hidden