Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSerialPort and std::bad_alloc

QSerialPort and std::bad_alloc

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Mark_
    wrote on last edited by
    #1

    Hi,
    I have a serial line which might receive a large quantity of data. Sometimes happens the application crashes with the following output:

    @
    terminate called after throwing an instance of 'std::bad_alloc'
    what(): std::bad_alloc
    @

    it's hard to debug but after a lot of trials it seems it happens during the "readAll" execution:

    @
    void mySerial::readyRead() {
    QByteArray buffer = serial()->readAll();
    [...]
    }
    @

    The data received is composed of short strings (about 50 byte each) every 10/15 ms.
    If I try to slow down the transmitter (say a string every 50 ms) the crash never happens.

    It's not mandatory to process each single message. I might live with some loss of packets. But I cannot live with such a crash!

    What would you suggest?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ankursaxena
      wrote on last edited by
      #2

      Whenever you want to read or write large amount of data. then u have to do in parts. means u have to mention that u'll read/write such amount of data in one time and this process will be happened till it is not completed.

      1 Reply Last reply
      0
      • _ Offline
        _ Offline
        _Mark_
        wrote on last edited by
        #3

        I process the incoming data as fast as possible. I mean the maximum length I get from readAll is less than 200 byte. I think this is not a very high payload for a x86!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved