From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: reading a text file into a string
Date: Tue, 20 Jul 2004 20:17:03 -0400
Date: 2004-07-20T20:17:03-04:00 [thread overview]
Message-ID: <nM-dnegXLbmdK2DdRVn-hQ@comcast.com> (raw)
In-Reply-To: <40fb8c00$1_1@baen1673807.greenlnk.net>
Martin Dowie wrote:
> Isn't there an arguement for defaulting to 250 characters/line? Can't
> remember what it was off the top of my head but it is ringing a bell...
There is, and it is probably worth spelling out for programmers...
If you are buffering lines and want to avoid unintentional cache
pressure, you should try to force buffers into a single cache line if
possible. But what size to use to do that?
Well first of all, Intel CPUs tend to have a 256-byte cache line. If a
cache read is in progress when another read occurs, the CPU may cut the
read off at 128 bytes. AMD processors (Athlon, Opteron, etc.) have
64-byte cache lines, but will normally read two lines on any memory
read. So Intel asks for 256 bytes, but may take 128, and AMD asks for
128 but may take 64. So 128 or 256-bytes is a good size for objects to
be fit in a single cache line.
However, in Ada a String will have a descriptor associated with it.
Also when a line is stored in a file, it will usually have some sort of
decoration, either a length field, a line terminator, or an appended null.
So what would like to do is:
subtype Index is Integer range 0..250;
type Buffer (Length: Index := 0) is record
Contents: String(1..Length);
end record;
for Buffer'Alignment use 256; -- or 128 on Athlons. ;-)
Language lawyer note: RM 13.3(32) says: "An implementation need not
support specified Alignments that are greater than the maximum Alignment
the implementation ever returns by default." This applies to subtypes,
for stand-alone objects RM 13.3(35) says: "For stand-alone library-level
objects of statically constrained subtypes, the implementation should
support all Alignments supported by the target linker. For example, page
alignment is likely to be supported for such objects, but not for subtypes."
So in theory you may need to put the 'Alignment clause on buffer objects
instead. GNAT however, won't even recognize those alignment clauses,
which IMHO is a shame:
------------------------------------------------------
package Test_Align is
subtype Index is Integer range 0..250;
type Buffer (Length: Index := 0) is record
Contents: String(1..Length);
end record;
Buff: Buffer;
for Buff'Alignment use 256;
end Test_Align;
-------------------------------------------------------
gnatmake test_align
gcc -c test_align.ads
test_align.ads:10:27: largest supported alignment for "Buff" is 4
gnatmake: "test_align.ads" compilation error
When the programmer can do something simple like this to improve program
performance, it should be supported by all compilers. (Notice that this
is an error, not a warning.) I can see not supporting the subtype case
due to the (potential) requirement for either large stack frames or
varying size stack frames. But for an object that can be allocated at
link time, I don't see why it shouldn't be supported.
--
Robert I. Eachus
"The flames kindled on the Fourth of July, 1776, have spread over too
much of the globe to be extinguished by the feeble engines of despotism;
on the contrary, they will consume these engines and all who work them."
-- Thomas Jefferson, 1821
next prev parent reply other threads:[~2004-07-21 0:17 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-15 17:27 reading a text file into a string zork
2004-07-15 17:49 ` Marius Amado Alves
2004-07-15 19:57 ` Nick Roberts
2004-07-15 17:59 ` Marius Amado Alves
2004-07-15 19:18 ` Nick Roberts
2004-07-15 19:18 ` Nick Roberts
2004-07-15 20:02 ` Nick Roberts
2004-07-16 1:23 ` Jeffrey Carter
2004-07-16 2:20 ` Steve
2004-07-16 2:26 ` Steve
2004-07-16 16:16 ` Jeffrey Carter
2004-07-16 17:45 ` Nick Roberts
2004-07-16 21:19 ` Randy Brukardt
2004-07-17 2:27 ` Robert I. Eachus
2004-07-17 11:31 ` Mats Weber
2004-07-17 15:52 ` Robert I. Eachus
2004-07-17 22:38 ` Jeffrey Carter
2004-07-18 13:44 ` zork
2004-07-19 8:07 ` Dale Stanbrough
2004-07-19 8:58 ` Martin Dowie
2004-07-21 0:17 ` Robert I. Eachus [this message]
2004-07-21 21:39 ` Randy Brukardt
2004-07-22 22:34 ` Robert I. Eachus
2004-07-23 0:49 ` Randy Brukardt
2004-07-23 21:56 ` Nick Roberts
2004-07-24 0:34 ` tmoran
2004-07-24 1:16 ` Nick Roberts
2004-07-24 1:42 ` Randy Brukardt
2004-07-24 15:14 ` Nick Roberts
2004-07-26 23:48 ` Randy Brukardt
2004-07-27 12:08 ` Nick Roberts
2004-07-27 23:24 ` Robert I. Eachus
2004-07-29 0:55 ` Randy Brukardt
2004-07-29 0:53 ` Randy Brukardt
2004-07-29 7:25 ` Martin Dowie
2004-07-29 20:08 ` Robert I. Eachus
2004-07-30 0:14 ` tmoran
2004-07-24 2:56 ` Robert I. Eachus
2004-07-19 11:51 ` Ada2005 (was " Peter Hermann
2004-07-19 12:51 ` Dmitry A. Kazakov
2004-07-19 13:01 ` Nick Roberts
2004-07-19 13:35 ` Martin Dowie
2004-07-19 17:22 ` Nick Roberts
2004-07-19 23:50 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox