Re: Strategies for indexing very large arrays
Maxim Yegorushkin wrote:
Jens Kilian wrote:
"Maxim Yegorushkin" <maxim.yegorushkin@gmail.com> writes:
Use size_t.
IIRC, the recommended index type for an overloaded
operator[] is ptrdiff_t.
ptrdiff_t is signed which might be a problem if your array is
bigger than a half of the virtual address space.
Which is highly unlikely if the size of each element is larger
than one. Generally speaking, a size_t can contain the number
of bytes in any single object, and a ptrdiff_t has an upper
limit of half that. So if the elements in an array are larger
than char's, it should be sufficient. I'd make the choice
dependent on whether I wanted to use an unsigned type or not.
(Normally, given the peculiarities of C++'s unsigned integral
types, it's better to avoid them for numerical values. On the
other hand, if you're already stuck with them in some contexts,
such as the STL, mixing signed and unsigned is a sure guarantee
of some surprises down the road.)
--
James Kanze GABI Software
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]