As of May 31, 2023, we have updated our Code of Conduct.

Hot answers tagged

10 votes

Is using malloc() and free() a really bad idea on Arduino?

I disagree with people who think you shouldn't use it or it is generally unnecessary. I believe it can be dangerous if you don't know the ins and outs of it, but it is useful. I do have cases where I ...
StuffAndyMakes's user avatar
9 votes

What's taking up so much RAM in an almost empty sketch?

I investigated this at some length a while back. On this page about putting constant data into program memory I obsessively tracked down every last byte of memory used in a small sketch. This was the ...
Nick Gammon's user avatar
  • 36.4k
9 votes

Sizeof variables and Due's RAM

sizeof doesn't return the number of elements. It returns the number of bytes. Since they are uint16_t arrays each element is 2 bytes - hence twice the size. The reason your last number is only 40928 ...
Majenko's user avatar
  • 104k
7 votes
Accepted

Executing machine code at runtime Uno

The microcontroller is executing one command at a time from..where? Flash memory directly. The AVR core can only execute instructions from Flash memory. It uses a two-bus system known as Harvard ...
Majenko's user avatar
  • 104k
6 votes
Accepted

Arduino constant vs Microchip PIC constant

const means different things in different contexts as far as storage goes. For a simple numeric value the compiler will generally replace the constant with the literal value. Any mathematics using ...
Majenko's user avatar
  • 104k
6 votes

Locally declared variable takes up global variable space in dynamic memory/SRAM

Isn't the space taken up by the local variable supposed to be freed up from the SRAM once the functions runs because I have declared the variable locally? This is correct. The local arrays you ...
Edgar Bonet's user avatar
  • 40.2k
5 votes
Accepted

Why is my SRAM so quickly filled? There are not more than 60 bytes

When you are asking yourself what is eating so much RAM, the first step is to look at the symbol table in the ELF file. If you use a makefile, you probably know where to find the ELF file. If you are ...
Edgar Bonet's user avatar
  • 40.2k
5 votes

Measure SRAM usage

Expanding on my previous comment... The RAM memory map of an AVR-based Arduino looks like this: ┌──────┬─────┬──────┬──────────┬───────┐ │ data │ bss │ heap │→ free ←│ stack │ └──────┴─────┴──────┴─...
Edgar Bonet's user avatar
  • 40.2k
5 votes
Accepted

Does the StringObject.reserve() function prevent memory fragmentation/leaks?

Reserving space will help reduce memory fragmentation, but much of what else you are doing is swamping that small improvement you have made. The biggest area of concern is your cutString function, ...
Majenko's user avatar
  • 104k
5 votes

Locally declared variable takes up global variable space in dynamic memory/SRAM

You must declare the array in global space or static, and make sure the function you pass the buffer pointer to knows it is in PROGMEM. void send22() { static unsigned int irSignal[] PROGMEM= {...
ratchet freak's user avatar
5 votes
Accepted

Is there a way to add external RAM (let's say 100 MB or 200 MB) in this audio buffer mixing context?

There are SRAM ICs / boards, however, don't expect 100 MB, more like 1 MB (with the pin numbers and connectivity / protocols that an Arduino offers). With Flash you can get much further, but it can ...
Michel Keijzers's user avatar
5 votes

Serial printing from Flash Memory (F() macro, PROGMEM, sprintf_P, SPTR)

First, the freeMemory() function that you used from Adafruit was originated from a github, I don't know about the __arm__ implementation, but for the avr, it is incomplete for handling the corner case ...
hcheung's user avatar
  • 1,174
4 votes

Is using malloc() and free() a really bad idea on Arduino?

Is it a really bad idea to use malloc() and free() with Arduino? The short answer is yes. Below are the reasons why: It is all about understanding what an MPU is and how to program within the ...
Mikael Patel's user avatar
  • 7,929
4 votes
Accepted

Array + Serial Monitor Problem

Use the F() macro for all double-quoted strings you print. Change lines like this: Serial.println(" degC."); ...to this: Serial.println( F(" degC.") ); This will save about 100 bytes of RAM. And ...
slash-dev's user avatar
  • 2,019
4 votes

Array + Serial Monitor Problem

You have likely run out of RAM. You have 431 integers in the look-up table alone. That equates to 862 bytes of SRAM. You also have a buffer of 75 floats, which equates to 300 bytes. This is in ...
sa_leinad's user avatar
  • 3,128
4 votes

Why is my SRAM so quickly filled? There are not more than 60 bytes

To elaborate on Edgar Bonet's answer and my comment under it, you cannot usefully put PROGMEM variables as local variables because local (non-static) variables have to be allocated on the stack. void ...
Nick Gammon's user avatar
  • 36.4k
4 votes

Confusion with storage of declared variables and volatile

That's just plain incorrect. The volatile keyword tells the compiler that the value of that variable may change at any time, and that therefore it must re-read the value every time you use it in your ...
Mark Smith's user avatar
  • 2,171
4 votes
Accepted

Which library to use for 23LC1024 SRAM 1 Mbit

SPI RAM has two modes of operation: single byte and "page mode". In single-byte mode you first send the read or write command followed by the (typically 3-byte) address and then read a byte. That's 5 ...
Majenko's user avatar
  • 104k
4 votes

Can I make existing libraries use external SRAM for the Arduino

Making a library use external SRAM is not an easy task. It can be cone, but it takes quite a bit of work. The best start would be to abstract the SRAM into a library that provides simple access to it....
Majenko's user avatar
  • 104k
4 votes

Sizeof variables and Due's RAM

The sizeof operator's result is number of bytes, not number of array elements. Your arrays in the program above have two bytes per element, hence twice as many bytes as elements. If you want to ...
James Waldby - jwpat7's user avatar
4 votes
Accepted

Is SRAM erased when putting Arduino into sleep_mode_pwr_down?

Generally, Atmega sleep modes do not erase RAM. Their memory is static and as long as voltage (above 2.7V I believe) is applied, data is held. However, this also depends on how you plan to wake up ...
mystery's user avatar
  • 321
4 votes
Accepted

Does the bootloader use some SRAM?

You did not specify what type of Arduino you are using. My answer is for the AVR-based ones. The bootloader does use RAM while it is running. However, once it handles control to your program, the ...
Edgar Bonet's user avatar
  • 40.2k
3 votes

Is there any way I can connect the RAM of a computer to Arduino?

No, you can't connect your normal desktop computer memory to your Arduino. For a number of reasons: Computer memory (at least for the past 20 years) is DDR SDRAM. That's Synchronous Dynamic RAM. It ...
Majenko's user avatar
  • 104k
3 votes

Inherent delay running EEPROM.read()

When I store it in the EEPROM, the extra time required to find it in EEPROM, pull it through the sketch, and then push it through to the db corrupts the data sourced from EEPROM and posts a jumbled ...
Majenko's user avatar
  • 104k
3 votes

Forensic security of Arduino (SRAM)

RAM memory looses its contents when it's powered off. However, this natural erasure process is not instantaneous: it can take several seconds, or even minutes. It has been demonstrated that cooling ...
Edgar Bonet's user avatar
  • 40.2k
3 votes

How to write data in RAM memory using Arduino Uno or Arduino Due?

Your program is already using the on board RAM: int a = 5; // This is RAM. Where did you think it goes? (This might go to a CPU Reg) int a[5000]; // This is RAM DDR3 RAMs require (typically) 1633 ...
xyz's user avatar
  • 359
3 votes

How to write data in RAM memory using Arduino Uno or Arduino Due?

DRAM of any kind requires a memory controller which is not present in any AVR device. Larger AVR devices such as the ATmega64A and ATmega128A do have an external memory bus that can be used for SRAM ...
Ignacio Vazquez-Abrams's user avatar
3 votes
Accepted

Local variable usage in SRAM not counted

Why is the local variable not counted? Let us start with the function availableMemory(), what does it do? int availableMemory() { extern int __heap_start, *__brkval; int v; return (int) &...
Mikael Patel's user avatar
  • 7,929
3 votes

Which library to use for 23LC1024 SRAM 1 Mbit

This was an excellent challenge for an SPI bus manager and device driver support library I have been working on. Below are some performance results for the SRAM (23LC1024) device driver (Arduino Uno @ ...
Mikael Patel's user avatar
  • 7,929

Only top scored, non community-wiki answers of a minimum length are eligible