On Oct 28, 2005, at 4:54 PM, Laurence Harris wrote:
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?
I want to end up with a library function that works exactly the same
as the existing Carbon file manager functions and that also works in
a plain Core Foundation project. Thus I'd like to code the function
similarly to the way it would be coded if Apple had written it, and I
believe that in this case it precludes C++.
, 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.
But with a C array I have to reallocate the entire array, rather than
just being able to add entries to the end of it as I go, as with a
linked list.
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.
Since I'm just iterating straight through this collection, a linked
list would be fine.
Before I used vectors, I used handles. I defined:
typedef FSRefPtr *FSRefHandle;
I then had some simple functions to work with them such as:
I didn't know about PtrAndHand! Very cool. Do you think it would be
more efficient to use a linked list since this will never require
relocating allocated memory (no doubt a costly operation)?
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