Go Down

Topic: Accident to use STL's <deque> on arduino 101. (Read 832 times) previous topic - next topic

daisukeura

Hello.
Thanks for taking care of my question the other day.


I use <deque> header on my 101.
But, my code is certainly crashed.


Deque stored some data (push_back()).
When stored data exceed 30, front data is deleted (pop_front()).
These deque has 31 or less data.
It is 4 (int size) x 10 (a number of deque) x 31 (a number of data) = 1.240 kbytes.
When 128-th push_back(), my arduino 101 has crashed.

How should I solve it?


I hope you will be able to provide the information.
Daisuke.



The code is below.

Code: [Select]

#include <deque>
#include <CurieTimerOne.h>

class TimeSeriesData
{
  public:
    std::deque<int> Dummy[10];

  public:
    unsigned int size()
    {
      return Dummy[0].size();
    }

    String outputData()
    {
      if (Dummy[0].size() == 0)
      {
        return outputDummyData();
      }
      else
      {
        return outputFactData();
      }
    }

    String outputFactData()
    {
      String output = "dummy";


      for (auto &a : Dummy)
      {
        a.pop_front();
        a.shrink_to_fit();
      }

      return output;
    }

    String outputDummyData()
    {
      String output = "dummy";

      return output;
    }


    void inputData()
    {
      for (auto &a : Dummy)
      {
        a.push_back(0);
      }
    };

    int getSize()
    {
      int ret = 0;
      for (auto a : Dummy)
      {
        ret += sizeof(int) * a.size();
      }
      return ret;
    }
};


TimeSeriesData Argon;

//SoftwareSerial mySerial(2, 3); // RX, TX

void setup() {
  Serial.begin(115200);
  while (!Serial) ;
  Serial.println("start");
  delay(100);
  CurieTimerOne.start(100000, &timerInt);
}

void loop() {
  if (Argon.size() > 30)
  {
    (Argon.outputData());
  }
}


void timerInt()
{
  int A = micros();
  static int h = 0;
  h++;

  Argon.inputData();

  int B = micros() - A;


  Serial.print("Time:");
  Serial.print(B);
  Serial.print("\t");

  for (auto &a : Argon.Dummy)
  {
    Serial.print(a.size());
    Serial.print("\t");
  }
  Serial.print(Argon.getSize());
  Serial.print("\t");

  Serial.println(h);



}



namespace std {
void __throw_bad_alloc()
{
  Serial.println("Unable to allocate memory");
}

void __throw_length_error(char const*e)
{
  Serial.print("Length Error :");
  Serial.println(e);
}
}
I am learning English now.
I'm sorry to my unskillful sentence.

alane143

Hello,
Deque is a c++ library, you can't use it in Arduino. Your code also uses some other c++ features (such as the auto keyword). Make sure you are writing code for arduino, not c++.

Romonaga

#2
Aug 19, 2019, 04:56 pm Last Edit: Aug 19, 2019, 05:00 pm by Romonaga
Hello,
Deque is a c++ library, you can't use it in Arduino. Your code also uses some other c++ features (such as the auto keyword). Make sure you are writing code for arduino, not c++.
Hmmm, If Arduino does not support STL, then what is this link all about?

https://github.com/mike-matera/ArduinoSTL
As far as Auto, auto is par of the c++ 11 standard.  I do believe it is supported, will have to test this tonight when I get home.

Go Up