|
Posted by Tony Marston on 07/12/06 08:22
"Andrew Poelstra" <apoelstra@localhost.localdomain> wrote in message
news:slrneb7fu0.ag.apoelstra@localhost.localdomain...
> On 2006-07-11, Tony Marston <tony@NOSPAM.demon.co.uk> wrote:
>>
>> "David Haynes" <david.haynes2@sympatico.ca> wrote in message
>> news:UXKsg.93009$NG4.13289@fe08.usenetserver.com...
>>> Tony Marston wrote:
>>>> I personally put the text for each language into a separate file, then
>>>> load that file into memory at the start of each script. Each individual
>>>> string is therefore taken from memory. Because there is only one disk
>>>> I/O
>>>> for the whole file, not each piece of text, it is very fast.
>>>
>>> Wouldn't the number of disk I/Os depend on the size of the file and the
>>> size of the read buffer in the device driver?
>>
>> Stop being pedantic. I'm talking about reading in the whole file into
>> memory
>> in one operation instead of doing a separate read for each piece of text.
>> So
>> in my code I perform a single read operation - how the operating system
>> or
>> file system handles this, such as splitting the operation into several
>> disk
>> accesses, or even retrieving from memory without accessing the disk at
>> all,
>> is largely irrelevant.
>>
>
> That's not pedantic; reading the whole file takes at least as much memory
> as the file is big. If you have a 4Kb disk cache, a 16Kb file will require
> 4 reads throughout the read instead of... 4 immediately. If your page is
> in high demand, saving 75% of memory isn't a minor accomplishment.
But which of these is more efficient?:
(a) Reading a file of 1000 entries into memory so that each entry can be
read from memory.
(b) Reading each of the 1000 entries from disk individually.
It's a toss up between memory usage or speed, and most people go for speed
and let the memory sort itself out.
--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
Navigation:
[Reply to this message]
|