Teensy 3 RAM size (how many bits per byte

Status
Not open for further replies.

CoClimber

New member
The Cortex processor of the Teensy3 is a 32 bit processor and I assumed that the SRAM was also 32 bit. The issue I have is that I am declaring an array:

int32_t FilteredDataArray[1000];

When I do this, the "Estimated memory use:" is 13,528 bytes.

If I declare the array as int8_t the memory use is 10,528.

I assume from this that the compiler is treating the ram as 8 bit. Can anyone confirm this and is there a fix, assuming that the ram is, in fact, 32 bit.

Thanks,
Doug
 
A 1000 element array of int32_t will occupy 4000 bytes and an int8_t array will occupy 1000 bytes. The difference between your two memory use figures is 3000 bytes - exactly as expected.

Pete
 
First, let's talk about memory usage.

An array of 1000 int32_t takes 4000 bytes, and an array of 1000 int8_t takes 1000 bytes. The rest of your program must be using 9528 byte of the RAM.

The USB and other library code that gets linked into all programs currently uses about 3800 bytes. Most of that is the buffers for USB packets. Some is buffers for other stuff which are currently getting linked into all programs, whether they're used or not. Reducing that is on my to-do list....

Now, about the RAM....

It is 32 bits wide. When you access a 32 bit integer, the compiler uses a single 32 bit bus cycle to fetch all 32 bits. By default, 32 bit integers are allocated in memory aligned to 4-byte boundaries, so they can be accessed efficiently.

The ARM processor is capable of accessing 8 bit and 16 bit data. The compiler allocates 16 bit variables aligned to 2 byte boundaries. 8 bit variables do not need any special alignment. That array of 1000 int8_t is packed into 1000 contiguous bytes. When you access each one, an ARM instruction is used to fetch only that 1 byte. The actual RAM is 32 bits wide. The buses within the chip are capable of moving 8, 16 or 32 bits on the bus. When the 32 bit bus is used to fetch bytes, the other 24 lines are ignored.
 
Also, I believe the Cortex-M4 has some logic to automatically issue 2 bus cycles if you access a 32 or 16 bit variable which spans a 32 bit boundary. Earlier ARM microcontroller chips (before the Cortex ones) did not have this. But it rarely matters, because the compiler will automatically allocate variables aligned to proper boundaries for the most efficient access. You can defeat that allocation with special attributes attached to the variables.
 
Status
Not open for further replies.
Back
Top