How does the memory consumption work in an arduino sketch

Hi,
I am using a Adafruit Feather M0 with RFM95. The on board memory is 256 Kb. I have created a header file which I am using to store some timing values on the nodes. The data type used for them is in unsigned long.

The header file looks something like this

unsigned long const UL_ts_20[][10][40]= 
{ 
{ 
{500321,3179670,4303016,5370107,6617938,8205190,9408348,10822571,11863338,13006416,14015112,16499621,17621432,18652684,19741890,20968584,21984985,24887315,27070395,28630344,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1032809,2048440,3055457,4145771,5977414,7460167,9019480,10908645,12378262,14039845,15188320,16753431,18272569,19442469,20976557,24182200,26084594,27562709,28793558,29991191,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
.
.
.

In total there are around 40,000 timestamps(TS) stored in the header file. The total memory used by the sketch is 194080 bytes (74%). Since long is 4 bytes, I am guessing the memory consumed by the timestamps should be around 160000 bytes.
In order to reduce the memory consumed, I changed the TS from long to int which is 2 bytes. I would imagine that the memory consumed would also become half, i.e. 80000 bytes by the TS but after compiling the sketch, it still shows the same figure for the memory used by the sketch.

unsigned int const UL_ts_20[][10][40]= 
{ 
{ 
{500,3180,4303,5370,6618,8205,9408,10823,11863,13006,14015,16500,17621,18653,19742,20969,21985,24887,27070,28630,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1033,2048,3055,4146,5977,7460,9019,10909,12378,14040,15188,16753,18273,19442,20977,24182,26085,27563,28794,29991,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},

How does the memory consumption works here?
Any help is appreciated.
Thank you

Long and int are the same size 4 bytes. You could try short int which is 2 bytes.

int - Arduino Reference It says here that int it 2 bytes??

this use SAMD.

Adafruit Feather M0 Basic Proto - ATSAMD21 Cortex M0

Look about SAMDs:
"

int

int which is short for integer is one of the most commonly used data type in Arduino. They are your primary data type for storing numbers.

Do note that int size varies from board to board. For example, in ATmega based Arduino boards like the Uno, Mega and Nano, an int uses 2 byte of memory and as a range of -32,768 to +32,767. While for the Due and SAMD based boards (eg. MKR1000, Zero), int uses 4 byte of memory and as a range of -2,147,483,648 to + 2,147,483,647.
"

Ref:
"https://www.seeedstudio.com/blog/2020/05/29/getting-started-with-arduino-data-types/

Thank you for clarification.

The official ISO C++ standard specifies a minimum size for the various types.

:smiley: Don't ask me any HARD questions about the language standard... I'm NOT an expert, but I have a outdated copy on a CD somewhere.

Also in your code you can use sizeof() function to return number of bytes a type uses if you have questions on other types.

The original C standard defined the data type lengths as the "natural" size for the processor, so it varied depending on the processor. I consider this a major flaw, since you could not guarantee what would happen if you changed processors. That is why I now mostly use the types from stdint.h or cstdint.h ( uint8_t, uint16_t etc).

Yes but it does not really matter as the spec was also saying

Each compiler is free to choose appropriate sizes for its own hardware, subject only to the the restriction that shorts and ints are at least 16 bits, longs are at least 32 bits, and short is no longer than int, which is no longer than long.

so you knew that if you wanted more than 16 bits maths, then you'd be better off with longs for example ➜ you wanted to code by following the spec, not the platform

of course having the fixed size types nowadays helps ensuring you don't throw away memory by having a storage too large (which was important then, and still is on small µC)

Yes, this Stops The Insanity.