[Development] Meaning of Q_PRIMITIVE_TYPE?
lars.knoll at nokia.com
lars.knoll at nokia.com
Sat Mar 31 14:37:47 CEST 2012
On 3/31/12 10:19 AM, "ext Olivier Goffart" <olivier at woboq.com> wrote:
>On Friday 30 March 2012 15:35:40 Thiago Macieira wrote:
>> On sexta-feira, 30 de março de 2012 18.41.46, Olivier Goffart wrote:
>> > On Friday 30 March 2012 12:23:59 Thiago Macieira wrote:
>> > > Use of QVarLengthArray should *only* be done with primitive types,
>>the
>> > > fixes applied to it during Qt 4.x lifetime notwithstanding. So the
>>user
>> > > must know that before he uses that class. If he's not sure, use
>>QVector.
>> >
>> > That is wrong. QVarLenghtArray can be use with every types.
>>
>> That statement ^^^
>>
>> > > Also, QVarLengthArray should zero-initialise, but it doesn't.
>> >
>> > It is documented not to.
>>
>> And this statement ^^^
>>
>> Are in contradiction. If it doesn't zero-initialise, then it doesn't
>> initialise. Then using it for non-PODs is dangerous.
>>
>> If it supports any type, then it must initialise them all.
>
>
>It initialize the types that are not marked as Q_PRIMITIVE_TYPE.
>The documentation even says that it is only primitive types that are not
>initialized
The problem is that users are not usually aware whether a class is
primitive or not.
>
>>
>> > But yes, it probably should. (we can add a Qt::Uninitialized
>>overload if
>> > we need it)
>>
>> I'd rather we removed support for non-primitives. The class wasn't
>>designed
>> for that.
>
>It was designed for that, and works well.
As the guy who wrote the first implementation: Originally it wasn't. It
was only there to help us place an array of primitive types on the stack.
It was basically there only to work around the fact that C++ doesn't allow
variable length arrays on the stack.
Cheers,
Lars
More information about the Development
mailing list