Solved Error allocating memory.
-
I'm developing a custom QQuickItem control to plot data in a graphic which can be scrolled show all values. I've detected that to store the data, if I use a dynamic container (like a QVector) then application receives a SIGV and the memory could not be allocated, however If the memory is allocated statically in the control (using a C array) then no signal is received and the application works fine.
Could you tell me why this happens? How can I use dynamic containers?
Thanks and Best Regards,
Joaquim Duran -
Hi,
How are you allocated that memory ? How are you using it ? What size is it ?
-
If you can paste the sample here, it would help us to check. Also as @SGaist suggested, check if you allocated memory.
-
Hello,
I'm developing a technical application which I need to plot 4 signals. To plot these signals of data, I'm developing a custom PlotControl, inherited from qquickitem. One of the requirements of the PlotControl is that the user should be able to flick the plot, with a gesture, to display previous data.
Currently, the control stores 30 seconds of data (30,000 samples: 30 seconds * 1,000 samples / second) but the it should store 4 minutes of data (240,000 samples: 240 seconds * 1,000 samples / second).
Currently the samples are stored in a vector of circular buffers:
typedef std::int32_t SampleType;
typedef boost::circular_buffer<SampleType> Signal;
typedef QVector<Signal> GroupSignals;To initialize the structure, the following code is used:
GroupSignals signals;
signals.resize(4);
Q_FOREACH( Signal & signal, signals ) {
signal.set_capacity(240000);
}The application allocates the memory to the buffers and it crashes because it receives a segmentation fault when it is assigning a property.
Joaquim Duran
-
What does the debugger tell you ?
-
#0 0x0805b6ff in EcgPlot::set_amplitud_correction (this=0x826ee58, ac=0.00100000005) at src/qml/ecgplot/EcgPlot.cpp:130 #1 0x0807da7d in EcgPlot::qt_static_metacall (_o=0x826ee58, _c=QMetaObject::WriteProperty, _id=0, _a=0xbfffecec) at moc/moc_EcgPlot.cpp:532 #2 0x0807de10 in EcgPlot::qt_metacall (this=0x826ee58, _c=QMetaObject::WriteProperty, _id=0, _a=0xbfffecec) at moc/moc_EcgPlot.cpp:593 #3 0xb6f7048c in QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) () from /usr/local/Qt-5.5.1/lib/libQt5Core.so.5 #4 0xb746866d in QQmlVMEMetaObject::metaCall(QMetaObject::Call, int, void**) () from /usr/local/Qt-5.5.1/lib/libQt5Qml.so.5 #5 0xb72a3137 in ?? () from /usr/local/Qt-5.5.1/lib/libQt5Qml.so.5 #6 0xb6f70461 in QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) () from /usr/local/Qt-5.5.1/lib/libQt5Core.so.5 #7 0xb74843a6 in QQmlPropertyPrivate::writeBinding(QObject*, QQmlPropertyData const&, QQmlContextData*, QQmlJavaScriptExpression*, QV4::Value const&, bool, QFlags<QQmlPropertyPrivate::WriteFlag>) () from /usr/local/Qt-5.5.1/lib/libQt5Qml.so.5 #8 0xb74f999c in QQmlBinding::update(QFlags<QQmlPropertyPrivate::WriteFlag>) () from /usr/local/Qt-5.5.1/lib/libQt5Qml.so.5 #9 0xb74fa065 in QQmlBinding::setEnabled(bool, QFlags<QQmlPropertyPrivate::WriteFlag>) () from /usr/local/Qt-5.5.1/lib/libQt5Qml.so.5 #10 0xb74fa0dd in QQmlBinding::setEnabled(QQmlAbstractBinding*, bool, QFlags<QQmlPropertyPrivate::WriteFlag>) () from /usr/local/Qt-5.5.1/lib/libQt5Qml.so.5 #11 0xb750359b in ?? () from /usr/local/Qt-5.5.1/lib/libQt5Qml.so.5 #12 0xb7486a62 in QQmlComponentPrivate::complete(QQmlEnginePrivate*, QQmlComponentPrivate::ConstructionState*) () from /usr/local/Qt-5.5.1/lib/libQt5Qml.so.5 #13 0xb7486b45 in QQmlComponentPrivate::completeCreate() () from /usr/local/Qt-5.5.1/lib/libQt5Qml.so.5 #14 0xb7486b8e in QQmlComponent::completeCreate() () from /usr/local/Qt-5.5.1/lib/libQt5Qml.so.5 #15 0xb74869ae in QQmlComponent::create(QQmlContext*) () from /usr/local/Qt-5.5.1/lib/libQt5Qml.so.5 #16 0xb7e52c48 in QQuickView::continueExecute() () from /usr/local/Qt-5.5.1/lib/libQt5Quick.so.5
The SIGV segmentation is received in:
void EcgPlot::set_amplitud_correction(float ac) { <----------- The ddd program points here. if (ac != m_amplitud_correction) { m_vertical_scaling_coef = calculate_vertical_scaling(m_sensitivity, ac); m_amplitud_correction = ac;
-
Are you sure the elements of
signals
are all of the capacity you set ?