Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Directory size function: problem with iteration



I would agree with Larry here - an STL vector is the way to go. One advantage over CFArray is that it will be typesafe - you don't need to use casts to access the data in the array.

Simply declare:

vector<FSRef> refVector;

To add an FSRef:

refVector.push_back( aRef );

To work with the list just treat it as a C array:

FSRef *aPointerThatIWillUseInASystemCall = &refVector[9];

(or whatever)

You can also use iterators, but you don't have to with vectors. A vector is as efficient for access as a "raw" C arrray.

The STL stuff *looks* cryptic, but it is worth a couple of hours getting the hang of it. Lets say later you decide that a linked list might be a better solution... just use a list in place of your vector and change no other code. Lets say that you want to make sure you only have unique FSRefs - this can be implemented in about 3 lines of code. It is very, very powerful.

Cheers,

Steve.

P.S. I've noticed too that almost all of Carbon is implemented internally in C++!

On 28 Oct 2005, at 23:22, Laurence Harris wrote:

On 10/28/05 6:15 PM, Eric Schlegel didst favor us with:



On Oct 28, 2005, at 3:07 PM, Lawrence Sanbourne wrote:


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++.


Well, not really. We use C++ all the time for implementation of C APIs.


In this case, personally, I'd use CFArray.


What advantages does a CFArray offer over non-CF array options?

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/steve% 40improvision.com


This email sent to email@hidden

Steve Baxter Software Development Manager Improvision +44-2476-692229

_______________________________________________
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
References: 
 >Re: Directory size function: problem with iteration (From: Laurence Harris <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.