0

i'm plotting real time usb-received data in Qt with Qcustomplot. for better speed, i want to allocate memory before data receive start. this is part of my code:

ui->plot_platform->graph(0)->data().data()->clear();
QVector<QCPGraphData> add_data(x);
ui->plot_platform->graph(0)->addData(add_data);

i do this at the start of data receiving. how i can determine size of x? it means how i can find max memory size that i can get from windows? is your solution safe from crashing?

javad
  • 15
  • 1
  • 8
  • 1
    Please consider starting the sentence with a capital letter and following all the grammar rules known to you. It's a friendly advice. Also please include all relevant parts of code in your question. You are asking something about `x`, while we don't know what `x` is. If your question is MS Windows specific, you could also be more specific about it. – cubuspl42 Jan 27 '18 at 17:01

1 Answers1

1

Even USB has a limited throughput, and thus you can estimate the maximum number of points (per time unit):=x which you want to reserve in QVector<QCPGraphData> add_data(x).

On the other hand as you allocate memory for QVector<QCPGraphData> on the stack, you may get a stack overflow if you reserve too many vector cells.

And btw: your need for speed might make you optimize at the wrong place as allocating some extra memory is not so time consuming as updating a plot with ui->plot_platform->graph(0)->addData(add_data); . Worth comparing with QWT (s. https://stackoverflow.com/a/24689918/4599792) ?

sirop
  • 181
  • 1
  • 13
  • I know my maximum transfer rate(20 MByte/s). but the problem is that i don't know the time that user want to save data. So i want to know the maximum memory size that i can use. even if i allocate memory simultaneously with data receiving, i am in danger! because i don't know how to allocate memory in QCustomplot without danger of crashing. I don't know if it has any method to say that i cant get more memory! any idea? – javad Jan 28 '18 at 08:14
  • I suppose that 20 Mbyte/s is the theoretical max transfer rate. But anyway: 1. Switch to Qwt as Qwt has a more compact plot array memory model, 2. Check the memory like in https://stackoverflow.com/a/64166/4599792 . 3. Save parts of your plot array to disk and update plot appropriately. – sirop Jan 28 '18 at 09:15