Page 1 of 1

RTC_DATA_ATTR std::deque

Posted: Thu Oct 25, 2018 7:06 pm
by czuvich
I'm trying to maintain a std::deque in slow memory (between sleeps) that is only initialized once. I wrote a small test program that declares the following (In Arduino IDE):

Code: Select all


RTC_DATA_ATTR std::deque<int> _queue;

setup() {
	// serial setup....
	_queue.push_back(100);
	Serial.println(_queue.size());
	
	esp_sleep_enable_timer_wakeup(5 * uS_TO_S_FACTOR);
        esp_deep_sleep_start();
}

I expected to see the _queue.size() to increment between sleep cycles; however, the queue size stays at 1. Is it possible to put dynamic structures into RTC?

Re: RTC_DATA_ATTR std::deque

Posted: Thu Oct 25, 2018 10:05 pm
by WiFive
RTC_NOINIT_ATTR but you also have to use a static array

Re: RTC_DATA_ATTR std::deque

Posted: Thu Oct 25, 2018 11:01 pm
by ESP_igrr
Not trivially: as all other standard containers, deque allocates memory from the heap. You can make it allocated from RTC slow memory, but you need to implement an allocator class and supply it when constructing the deque, in addition to placing deque itself into the RTC memory. See https://en.cppreference.com/w/cpp/memory/allocator. But as WiFive points out, using a static array might be an easier option...

Re: RTC_DATA_ATTR std::deque

Posted: Fri Oct 26, 2018 1:58 am
by czuvich
Thanks all. I'll probably end up with a static array of char[] to store my queue messages. And using FRAM only as needed.