Questions tagged [memory-usage]

Use this tag for questions about memory usage on the Arduino.

Filter by
Sorted by
Tagged with
11
votes
5answers
3k views

Why is it considered bad practice to use the 'new' keyword in Arduino?

I previously asked this question: Is it required to delete variables before going to sleep? On that question, @Delta_G posted this comment: ... Really on a microcontroller I would create the object ...
11
votes
1answer
16k views

Can I write to Flash Memory using PROGMEM?

On the documentation of Arduino, I quote: http://playground.arduino.cc/Learning/Memory Note: Flash (PROGMEM) memory can only be populated at program burn time. You can’t change > the values in ...
9
votes
1answer
805 views

Overview of compiled code size

When I compile my code, the Arduino IDE returns the binary sketch size in byte. Is there a good way to find out (approximately) what function or what part of my code takes up how much memory in ...
9
votes
5answers
5k views

Efficient algorithm/data structure to calculate moving averages

Currently I am developing a graphic LCD system to display temperatures, flows, voltages, power and energy in a heat pump system. The use of a graphic LCD means that half of my SRAM and ~75% of my ...
8
votes
3answers
9k views

PROGMEM: do I have to copy data from flash to RAM for reading?

I have got some difficulties understanding the memory management. Arduino documentation says, it is possible to keep constants like strings or whatever I don't want to change during runtime in ...
8
votes
5answers
4k views

How is stack memory used for fuctions and local variables?

I wanted to save some values to the EEPROM and also wanted to free up SRAM by avoiding some variable declarations, but EEPROM memory is byte wise. If I want to store an int value, I have to use some ...
8
votes
2answers
1k views

memory usage “dos and don'ts”

Though I've written C/C++ code for a long time, the unseen limitations on how memory was consumed on various MCU and SOC programming platforms have often tripped me up. As I'm about to build up code ...
8
votes
2answers
4k views

OOP vs Inline with Arduino

I have been programming for quite a while now but I am new to Arduino and AVR Programming. The main question I have about programming these Micro-controllers is are there major differences in ...
8
votes
1answer
1k views

Is there any way to run binary code from RAM?

I am looking for an inexpensive single board computer that I could program in assembly language, using limited facilities to load the object code from a PC and simple I/O peripherals. Ideally I would ...
7
votes
4answers
16k views

Can you access the EEPROM of an ATtiny with Arduino Code?

I'm attempting to reduce the amount of RAM being used by my program by writing some values to the EEPROM of my micro controller. I'm currently programming on the ATtiny85 which has 512 Bytes of EEPROM....
7
votes
1answer
19k views

int VS uint8_t VS uint16_t

This question is quite clear. What are the differences between an int, an uint8_t, and an uint16_t. I know it has to do with bytes and memory but can someone clarify me a bit? Things I want to know: ...
6
votes
1answer
519 views

Understanding global variables on Arduino

I am rewriting a set of LED manipulation functions to be more object oriented, and I have found that, mysteriously, my global variable memory space has been over consumed, despite a reduction of the ...
5
votes
4answers
2k views

What are the traditional ways to optimize program memory usage?

While doing big projects using Arduino boards (Uno, Atmega328P MCU). I used to get warnings like this Sketch uses 13764 bytes (44%) of program storage space. Maximum is 30720 bytes. Global variables ...
5
votes
3answers
4k views

When to use PROGMEM?

I believe PROGMEM is used to store large data (e.g. strings) that don't change. So it frees up the SRAM. in the Ardunio Reference it is mentioned that. "Using PROGMEM is also a two-step procedure. ...
5
votes
3answers
3k views

Detailed analyse of memory usage

When compiling a sketch, after linking, the build outputs a kind of forecast on RAM usage, e.g.: Minimum Memory Usage: 1456 bytes (71% of a 2048 byte maximum) Is it possible to somehow get a ...
4
votes
3answers
2k views

Memory usage: #define vs. static const for uint8_t

I'm writing an Arduino library to communicate with an I2C device, and I'm wondering what the best way is to declare all the register addresses so as to save memory. Using #defines: #define ...
4
votes
1answer
9k views

Store String using F() Macro

I'm new to the Arduino and do not quite understand the F() macro yet. In my code, I have a String, and as I want to transfer it via WebServer, I need to write it to the answer. Somehow I need to ...
4
votes
2answers
206 views

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

I'm coding a music sampler device: for fast playback / minimal latency (only a few milliseconds), it's better to have all audio .wav samples we want to use in RAM, so that when some of them are ...
4
votes
3answers
5k views

Arduino String memory allocation

When a String variable is declared and modified inside a function, where does it go? To the heap(as string declaration is a part of dynamic memory allocation) or to the stack(as it is a part of ...
4
votes
1answer
393 views

Why does this code execute?

After experiencing failures of my Arduino projects due to low memory, I decided to do some research into it so I could understand better where the problems were. I eventually came to this code: void ...
4
votes
2answers
76 views

Use large variables without using much memory

I've wired up a dot matrix, and I display characters on the screen by using something like the example code below. The Char_B variable is a global variable in a library used by the Arduino, and ...
3
votes
4answers
542 views

How can a function/method determine if a const array passed in is PROGMEM (flash) or not (RAM)?

Is it possible for a function/method to know if a constant array that has been passed in is in flash or RAM? If I have a method or function that receives a constant array that is in RAM, the array is ...
3
votes
4answers
293 views

Can you help me trim my code?

First of all I want to be clear, I'm not very skilled in programming methods, all the C I learned was for various Arduino projects. That being said, I just finished a project that reads some data ...
3
votes
2answers
4k views

What is the best way to get more RAM for a sound buffer?

The problem: How to extend the memory for a sound buffer (intensively used) if: SD card library supports only one file open at a time (and I have one open already) EEPROM chips are able to stand ...
3
votes
2answers
561 views

How to correctly pack an unsigned long from 3 unsigned chars?

I would like to use 652 unsigned long values on an Arduino Uno, but it doesn't look like there's enough memory. I thought about the splitting unsigned long values to 3 unsigned chars to store in ...
3
votes
3answers
921 views

Is this function subject to memory fragmentation?

I'm trying to understand if the following bit of code is subject to memory fragmentation. Let's say I incrementally build a string within a function and I don't know how large the string should be. ...
3
votes
2answers
2k views

What is the memory expense of creating a String from a char array?

I'm writing a little API for processing email messages in Arduinos. Obviously, I need to keep memory use down, but I also want to allow the end user to use the String functions (like indexOf) to ...
3
votes
2answers
2k views

At what level does low dynamic memory effect performance?

I have a few Arduino sketches that take 70-90% of dynamic memory. It seems that over 70%, the compiler gives the warning: Low memory available, stability problems may occur. but otherwise I wasn't ...
3
votes
1answer
131 views

Local variable usage in SRAM not counted

I use the following code to print the currently used SRAM space: // this function will return the number of bytes currently free in RAM // written by David A. Mellis // based on code by Rob Faludi ...
3
votes
1answer
372 views

Question of proper usage for F Macro

Here are three use cases. Are all preferred or is the use of the F() macro pointless on some? 1. Serial.println(F("some string"); // definitely useful here 2. String str = F("some string"); Serial....
3
votes
1answer
333 views

Single #include pulls in all libraries

I am tracking down the memory usage of an Arduino-like project I am working on (not a real Arduino, but has same microcontroller and it uses the Arduino build environment, version 1.6.8). I have some ...
2
votes
3answers
5k views

Storing an array of function pointers

I have some Arduino code that looks like: char packet = ser.read(); switch(packet){ case 'a': someobj.somefunc(); break; case 'b': otherobj.otherfunc(); ...
2
votes
2answers
373 views

Lowest memory consumption for arrays

I made a little joystick input recorder that stores the joystick state (8 directions + fire) and the time (how long was a button or direction pressed). Example data would be like this (i = input, t = ...
2
votes
3answers
774 views

Reducing Memory Usage lots of Floats

Im using an Arduino Uno - All code at github.com/robbrad/AirQuality Current sketch usage: Sketch uses 23186 bytes (71%) of program storage space. Maximum is 32256 bytes. Global variables use 1428 ...
2
votes
1answer
1k views

What is using up all the RAM in my program?

I am running a program on the ATtiny and for some reason I am way over the 512 bytes of RAM that are available to me. This is confusing because when I did the math by hand I should have 432 bytes. ...
2
votes
3answers
5k views

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

I know that it is possible to write data in ROM(Read Only Memory). But what about if I want to write data in RAM(Random Access Memory)? Can I do it using "Arduino Uno R3"? RAM is normally associated ...
2
votes
1answer
890 views

Measure SRAM usage

I am using an Arduino with 2048 bytes of SRAM. I have a complex project so that it is no longer obvious how much SRAM it would use in total (there is not one large dominant object but many different ...
2
votes
1answer
414 views

Sending >255 bytes array to arduino

I am trying to send a 50x50 bitmap bytearray from my python client to arduino where it should be displayed on a screen. I need to receive 350 bytes to have the data to show the bitmap but as soon as ...
2
votes
1answer
532 views

Are my arrays stored in sram or in Flash?

I have the following memory allocation: unsigned char g1[]={ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ....0x00 ,0x00 ,0x00 ,0x00 ,0x00 }; g2[]={ 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 .......
2
votes
2answers
90 views

Help with a Memory Issue

Below is some code that I'm writing to concurrently run "animations" on the same strip of NeoPixels. When I try to make use of the Serial monitor to control the program functions, I just get a bunch ...
2
votes
1answer
1k views

Is the a low memory alternative to SoftwareSerial?

I'm running a program on a ATtiny85 and running into problems because of a lack of available RAM. When I ran avr-nm on my ELF file I found that SoftwareSerial was taking up a lot of RAM even though I'...
2
votes
1answer
929 views

Am I Running Out of RAM Or Not?

I'm attempting to drive 300 TM1803 RGB LEDs from an Arduino Uno using the FastLED library. My code works fine for 100 LEDs, but when I go to 150, the arrays that store LED values and my sensor data ...
2
votes
3answers
536 views

Is it possible to configure FRAM memory for use as stack and heap?

I'm using the Adafruit I2C FRAM breakout board with my Nano and it works as advertised, but every time I write a variable to this thing I have to use library function calls with addressing. This makes ...
2
votes
2answers
420 views

Arduino Uno - why doesn't memory leak crash the program?

I wrote this test program: void loop() { digitalWrite(13,1); delay(300); digitalWrite(13,0); delay(300); void *a = malloc(10000000000000000000000000000000000000000); } Curiously, ...
2
votes
1answer
31 views

Connect SDRAM to STM32

Well, first of all hello to everything and thanks for reading my question. I am designing a board with STM32F730R8T6 MCU, and I want to connect MT48LC16M16A2P-6A to it which is 4MB SDRAM chip. The ...
2
votes
1answer
7k views

String to persistent memory (EEPROM?)

I am creating a server node that I want to be able to save the wifi SSID and the password into persistent memory so that when it starts ups it can connect to the network. I have looked for several ...
2
votes
1answer
2k views

I need help with U8GLIB library

I have a project which uses a 128x64 oled display. I have to use the U8GLIB as the available displays change from SSD1306 to SSH1106 depending on when you buy it which that library covers both ...
2
votes
1answer
1k views

Arduino Nano memory issue. SD card and LCD screen together

When i am uploading my code to arduino nano, i am getting message about high dynamic memory usage (87%): Sketch uses 17,628 bytes (57%) of program storage space. Maximum is 30,720 bytes. Global ...
2
votes
1answer
463 views

What will use less memory, an array or if … else?

I'm trying to make my sketch smaller. Right now I use an array for the AM/PM part of my time display. My thinking is this makes it easy to change the formatting: char* ampms[]= {"am", "pm"}; void ...
2
votes
2answers
249 views

Is there any way that the values here be converted to another variable and not string?

int val1 =(mfrc522.uid.uidByte[0]); int val2 =(mfrc522.uid.uidByte[1]); int val3 =(mfrc522.uid.uidByte[2]); int val4 =(mfrc522.uid.uidByte[3]); String valA=String(val1); String valB=String(val2); ...