3

QByteArray のメモリ レイアウトを見つけようとしています (パラメーターとして QByteArray を持つ DLL とインターフェイスする必要があるため)。元の QT ソースから、以下を抽出しました。

template <typename BaseClass> struct QGenericAtomicOps {
};
template <int size> struct QBasicAtomicOps : QGenericAtomicOps < QBasicAtomicOps<size> > {
};
template <typename T> struct QAtomicOps : QBasicAtomicOps < sizeof( T ) > {
    typedef T Type;
};
template <typename T>
struct QBasicAtomicInteger {
    typedef QAtomicOps<T> Ops;
    typename Ops::Type _q_value;
};
typedef QBasicAtomicInteger<int> QBasicAtomicInt;
struct RefCount {
    QBasicAtomicInt atomic;
};
typedef void* qptrdiff;
struct QArrayData {
    RefCount ref;
    int size;
    UINT alloc : 31;
    UINT capacityReserved : 1;
    qptrdiff offset; // in bytes from beginning of header
};
template <class T>
struct QTypedArrayData
    : QArrayData {
};
struct QByteArray {
    typedef QTypedArrayData<char> Data;
    Data *d;
};

(このコードでは、データ レイアウトのみに関心があるため、すべての関数を削除しました。)

したがって、メモリレイアウトは次のようになると思います。

QByteArray
    QArrayData * Data; // pointer to the array-data struct.

QArrayData
    int ref; // the reference counter
    int size; // the used data size
    UINT alloc:31; // the number of bytes allocated
    UINT reserve:1; // unknown
    void* offset; // pointer to real data

これは正しいです?私は特に「オフセット」について疑問に思っています。コードを見ると、実際のデータはオフセットの直後に開始され、構造体の一部であるという印象を受けました。実際のデータが「ArrayData」ヘッダーの前にある可能性もあるようです。

したがって、「d」は次のレイアウトのいずれかを指すことができます。

1. [ref|size|alloc|reserve|offset|--the real data--]
2. [--the real data--|ref|size|alloc|reserve|-offset]

これは正しいです?

カール

4

0 に答える 0