Re: Comparing two images
Re: Comparing two images
- Subject: Re: Comparing two images
- From: Alastair Houghton <email@hidden>
- Date: Sat, 29 Nov 2003 17:31:52 +0000
On 29 Nov 2003, at 11:27, Lorenzo wrote:
>
Hi Alastrair,
>
your Cocoa routine worked flawlessly. Thank you.
>
I will try to use also the BSD one.
>
>
And as far as NSData *dataA = [fileA readDataOfLength:BUFFER_SIZE];
>
are you sure it allocates the memory for NSData any time?
>
Maybe, if I don't release NSData, it reuses the same memory block
>
filling
>
with the new data. Any idea? Where should I get further informations
>
like
>
this on this API?
Even if Foundation does cache NSData objects, it is unlikely IMHO that
it caches the memory buffers they use because they are often rather
large (it might have a special case for small buffers, though). You
could try using the malloc debug features (MallocHelp et al) to obtain
a log of the memory allocations and frees that a program does when it
reads an NSData from a file, releases it and then does another read.
If you find that the -bytes pointer for the two NSDatas is the same,
and in the malloc trace you see only a single allocation of that
pointer, then it may indeed be caching the memory block.
Alternatively, if it matters, ask Apple. Or disassemble the code and
take a look.
(Of course, if we're lucky, then someone who knows for certain might
even jump in with an answer ;->)
>
Last, I am really curious to know how you chose the value 131072
>
to define the buffer size.
>
#define BUFFER_SIZE 131072
A guess, based on experience (131072 is 128KB). There is a trade-off
between making this buffer large (which reduces I/O overhead) and
making it smaller (which reduces I/O time per buffer comparison as well
as reducing your program's memory footprint). Generally what you find
is that increasing this buffer size from 4KB up to around the 64KB to
256KB mark produces a reasonable performance gain, but after that the
returns start to diminish (so, for example, a 10MB buffer probably
wouldn't be any faster than a 5MB buffer, and might even be slower).
If you want to optimise the routines I posted, then changing this
number is a good place to start; I wouldn't make it anything other than
a multiple of 4KB, because that is the system page size as well as the
normal block size on HFS+ filesystems. Using anything other than a
multiple of 4KB will force Mac OS X to do additional buffering and
copying that it wouldn't otherwise need to do.
Kind regards,
Alastair.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.