FROM : Steve Christensen
DATE : Sat May 21 01:27:40 2005
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;
}
DATE : Sat May 21 01:27:40 2005
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;
}
| Related mails | Author | Date |
|---|---|---|
| Julian | May 20, 18:09 | |
| Brian Bergstrand | May 20, 18:42 | |
| Daniel Jalkut | May 20, 18:42 | |
| Jim Correia | May 20, 18:50 | |
| Chris Parker | May 20, 19:00 | |
| Jim Correia | May 20, 19:00 | |
| James Bucanek | May 20, 19:20 | |
| Julian | May 20, 19:22 | |
| Daniel Jalkut | May 20, 19:57 | |
| J.M.Brough | May 20, 20:06 | |
| Rosyna | May 21, 01:26 | |
| Steve Christensen | May 21, 01:27 |






Cocoa mail archive

