KcFnMi
KcFnMi

Reputation: 6171

Should a big QByteArray be heap allocated?

On Windows on a Qt C++ application, I'm reading image data from an instrument. The instrument driver gives me a pointer to the data and basic image information:

In other words, an image file is almost 3MB.

I'm storing that on a QByteArray, on that stack.

Is that 3MB too big for the stack? Should that be on the heap?

Upvotes: 1

Views: 207

Answers (1)

selbie
selbie

Reputation: 104569

QByteArray does its own heap allocation (in the constructor or whenever it needs to grow). So you can declare a QByteArray of any size on the stack. When the variable goes out of scope, the destructor will release the memory.

The C++ standard library equivalent is std::vector<uint8_t> or std::vector<char>.

Upvotes: 3

Related Questions