首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > QT开发 >

QVector可以寄存数据的内存大小是多少

2013-12-11 
QVector可以存放数据的内存大小是多少?我试了下,我的电脑可以放60M左右的数据。栈内存是1~2M,堆更大,但vect

QVector可以存放数据的内存大小是多少?
我试了下,我的电脑可以放60M左右的数据。栈内存是1~2M,堆更大,但vector是在哪分配的内存呢?
[解决办法]
应该是堆内存。我的电脑上QVector<__int64>可以放67100000个数据,如果放67200000则失败。
[解决办法]

struct Q_CORE_EXPORT QVectorData
{
    QBasicAtomicInt ref;
    int alloc;
    int size;
#if defined(QT_ARCH_SPARC) && defined(Q_CC_GNU) && defined(__LP64__) && defined(QT_BOOTSTRAPPED)
    // workaround for bug in gcc 3.4.2
    uint sharable;
    uint capacity;
    uint reserved;
#else
    uint sharable : 1;
    uint capacity : 1;
    uint reserved : 30;
#endif

    static QVectorData shared_null;
    // ### Qt 5: rename to 'allocate()'. The current name causes problems for
    // some debugges when the QVector is member of a class within an unnamed namespace.
    // ### Qt 5: can be removed completely. (Ralf)
    static QVectorData *malloc(int sizeofTypedData, int size, int sizeofT, QVectorData *init);
    static QVectorData *allocate(int size, int alignment);
    static QVectorData *reallocate(QVectorData *old, int newsize, int oldsize, int alignment);
    static void free(QVectorData *data, int alignment);
    static int grow(int sizeofTypedData, int size, int sizeofT, bool excessive);
};


看这段代码,你就可以看出,QVector是分配在heap上的。所有容器类一般都是分配在堆上的

热点排行