RTC_DATA_ATTR std::deque

czuvich
Posts: 36
Joined: Tue Sep 04, 2018 1:58 am

RTC_DATA_ATTR std::deque

Postby czuvich » Thu Oct 25, 2018 7:06 pm

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?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: RTC_DATA_ATTR std::deque

Postby WiFive » Thu Oct 25, 2018 10:05 pm

RTC_NOINIT_ATTR but you also have to use a static array

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: RTC_DATA_ATTR std::deque

Postby ESP_igrr » Thu Oct 25, 2018 11:01 pm

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...

czuvich
Posts: 36
Joined: Tue Sep 04, 2018 1:58 am

Re: RTC_DATA_ATTR std::deque

Postby czuvich » Fri Oct 26, 2018 1:58 am

Thanks all. I'll probably end up with a static array of char[] to store my queue messages. And using FRAM only as needed.

Who is online

Users browsing this forum: Bing [Bot] and 120 guests