• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Obtain directory size.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obtain directory size.


  • Subject: Re: Obtain directory size.
  • From: Steve Christensen <email@hidden>
  • Date: Fri, 20 May 2005 16:27:40 -0700

On May 20, 2005, at 10:57 AM, Daniel Jalkut wrote:

On May 20, 2005, at 9:42 AM, Daniel Jalkut wrote:


  const ItemCount kMaxEntriesPerFetch = 256;   ItemCount actualFetched;   FSRef fetchedRefs[kMaxEntriesPerFetch];   FSCatalogInfo fetchedInfos[kMaxEntriesPerFetch];

Looking more carefully at my own code, I would probably suggest changing this so that the allocations for the fetchedRefs and fetchedInfos are made outside of the recursion. 


I'm now afraid that this could easily exhaust the stack if a folder is sufficiently deep.  FSRefs and FSCatalogInfos aren't small!

Daniel


You actually do need storage for the FSRef and FSCatalogInfo at each recursion level, otherwise you're stomping on the [shared] storage. Probably better to malloc/free the storage in each call to fastFolderSizeAtFSRef instead, something like this:

- (unsigned long long) fastFolderSizeAtFSRef:(FSRef*)theFileRef
{
    unsigned long long totalSize = 0;
    FSIterator    thisDirEnum;

if (FSOpenIterator(theFileRef, kFSIterateFlat, &thisDirEnum) == noErr)
{
const ItemCount kMaxEntriesPerFetch = 256;


        struct SFetchedInfo
        {
            FSRef           fFSRefs[kMaxEntriesPerFetch];
            FSCatalogInfo   fInfos[kMaxEntriesPerFetch];
        };

// might as well allocate all the storage with a single call...
SFetchedInfo* fetched = (SFetchedInfo*) malloc(sizeof(SFetchedInfo));


if (fetched != NULL)
{
ItemCount actualFetched;
OSErr fsErr = FSGetCatalogInfoBulk(thisDirEnum, kMaxEntriesPerFetch, &actualFetched,
NULL, kFSCatInfoDataSizes | kFSCatInfoNodeFlags, fetched->fInfos,
fetched->fFSRefs, NULL, NULL);
[...]


            free(fetched);
        }

        FSCloseIterator(thisDirEnum);
    }

    return totalSize;
}

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Obtain directory size. (From: Julian <email@hidden>)
 >Re: Obtain directory size. (From: Daniel Jalkut <email@hidden>)
 >Re: Obtain directory size. (From: Daniel Jalkut <email@hidden>)

  • Prev by Date: Re: Obtain directory size.
  • Next by Date: Re: Lots of NSTimers?
  • Previous by thread: Re: Obtain directory size.
  • Next by thread: Re: Obtain directory size.
  • Index(es):
    • Date
    • Thread