Re: problem with applying md5 to data
Re: problem with applying md5 to data
- Subject: Re: problem with applying md5 to data
- From: Quincey Morris <email@hidden>
- Date: Wed, 29 Jun 2011 12:18:47 -0700
On Jun 29, 2011, at 11:32, Wilker wrote:
> Just for curiousity, if I do the line:
>
> const uint8_t* buffer = [fileData bytes];
>
> it will not read the entire file? or these address are pointed direct on disk so they are load on demand?
[fileData bytes] is a pointer to some memory address or other, in your application's virtual memory address space. The actual pages of data don't exist yet, they are indeed "loaded" on demand. The demand will happen when CC_MD5_Update tries to retrieve bytes to update its calculations. As its internal pointer increments into each new page, its data accesses will cause VM faults, which will cause the pages to be read from disk, which in this case is your video file.
That's why this is efficient. A "normal" read will transfer pages of data into the system's disk cache, then transfer some of it again into your application's address space, and if those pages in your address space happen to be swapped out sometime, your data is written *back* to disk (in the system VM backing store) for later rereading. Using mapped reads with no caching avoids all of that.
> also, just to mean if I understand here:
>
> CC_MD5_Update(&md5, buffer + byteOffset, byteLength);
>
> in the sum "buffer + byteOffset", in case, adding a number to an array pointer will change it offset?
'buffer' is not an array, it's just a pointer. It's a pointer to an array of bytes, if you choose to think of it that way, but so are all pointers, if you choose to think of them that way.
Think of it this way. You were using 'getBytes:range:NSMakeRange(offset,length)' to copy the bytes to a local buffer. That buffer must have copied the bytes *from* somewhere. The place where the bytes are being copied from is, literally, '[fileData bytes] + offset', and NSData's API makes it perfectly legal to go to the source yourself._______________________________________________
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