[Interest] 64 bit capable QVector

Thiago Macieira thiago.macieira at intel.com
Tue Sep 3 20:48:05 CEST 2013


On terça-feira, 3 de setembro de 2013 22:18:39, Constantin Makshin wrote:
> Could you please explain (or give a link to an article or something like
> that) the reasons Qt developers used to choose signed 32-bit integer for
> this purpose?
> Signed 32-bit container sizes, i.e. number of elements in a container,
> would be acceptable (considering the equation 'n * sizeof(T)' for the
> amount of memory consumed by the array alone) but why use them to
> calculate and store sizes of allocated memory blocks?

For two reasons:

1) it's signed because we need negative values in several places in the API: 
indexOf() returns -1 to indicate a value not found; many of the "from" 
parameters can take negative values to indicate counting from the end. So even 
if we used 64-bit integers, we'd need the signed version of it. That's the 
POSIX ssize_t or the Qt qintptr.

This also avoids sign-change warnings when you implicitly convert unsigneds to 
signed:
	-1 + size_t_variable		=> warning
	size_t_variable - 1		=> no warning

2) it's simply "int" to avoid conversion warnings or ugly code related to the 
use of integers larger than int.

io/qfilesystemiterator_unix.cpp:
        size_t maxPathName = ::pathconf(nativePath.constData(), _PC_NAME_MAX);
        if (maxPathName == size_t(-1))

io/qfsfileengine.cpp:
    if (len < 0 || len != qint64(size_t(len))) {

io/qiodevice.cpp:
qint64 QIODevice::bytesToWrite() const
{
    return qint64(0);
}

                    return readSoFar ? readSoFar : qint64(-1);


> 
> On 09/03/2013 08:42 PM, Thiago Macieira wrote:
> > On terça-feira, 3 de setembro de 2013 19:33:47, Mehmet İpek wrote:
> >> Btw, size
> >> limit of QVector is 2^31 in 64 bit platforms too?
> > 
> > Yes. All Qt container classes use a signed int for sizes.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130903/dfbb15ea/attachment.sig>


More information about the Interest mailing list