Re: Newbie question: error in creating a NSData object using handle (Resource Management)
Re: Newbie question: error in creating a NSData object using handle (Resource Management)
- Subject: Re: Newbie question: error in creating a NSData object using handle (Resource Management)
- From: Ken Thomases <email@hidden>
- Date: Wed, 25 Jun 2008 01:36:40 -0500
On Jun 25, 2008, at 1:19 AM, Tran Kim Bach wrote:
Hi folks,I'm a newbie to Cocoa.
Recently, I'm working on a project relating to Resource Management.
In my project, there's a part that I'm reading through the resources
in a
resource file.
I'm using:
int count = CountResources( typeName );
to get all resource that has the type "typeName", then loop through
this
resource list to take resource data out.
for (n = 1; n <= count; n++)
{
Handle dataHandle = Get1IndResource( type1, n);
....
NSData *data = [NSData dataWithBytes: *dataHandle length:
GetResourceSizeOnDisk(dataHandle)]; // I GOT AN ERROR HERE
What do you mean "GOT AN ERROR"? What error? How did it manifest?
//using data
struct A_STRUCT aStruct;
memcpy(& aStruct,[data bytes], [data length]);
}
After several times looping through the list, I got an error in the
line
above.
But if I use data directly, like the following code, there is no error
occurred.
memcpy(&pgControlRes,*dataHandle, GetResourceSizeOnDisk(dataHandle));
Any suggestions for my problem.
I highly appreciate all your helps.
You don't show if you're:
1) Checking if dataHandle is NULL
2) Checking if *dataHandle is NULL
3) If (1) or (2), checking ResError()
4) Disposing of dataHandle with ReleaseResource()
Also, in the pseudo-code you provide, the NSData objects will
accumulate in the autorelease pool until some point after your "for"
loop. You can try using an autorelease pool inside the loop so that
the NSData objects are released after each iteration. You may just be
exhausting memory. For the case where you're not using NSData, the
memory exhaustion might not happen since you're not storing the data
twice in memory (once in the handle, once in the NSData), but would if
there were twice as many resources.
Cheers,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden