user1499: I set out to see how much space some arrays have. I used this test code
bool state = false;

uint16_t BuffA[46000];
uint16_t BuffB[20000];
uint16_t BuffC[20000];
uint16_t all = 0;

void setup(){
Serial.begin(9600);
}

void loop(){
if (state==false){
Serial.println(sizeof(BuffA));
Serial.println(sizeof(BuffB));
Serial.println(sizeof(BuffC));
all = sizeof(BuffA) + sizeof(BuffB) + sizeof(BuffC)
Serial.println(all);
state = true;
  }
}

I got this answer from the serial:
92000
40000
40000
40928


Why are the results doubled from those i initiated? Shouldn't the first one be 46kb and the other two 20kb?
Why is the last value only 40928?
The RAM of Due is 96kb. Does this mean that with the initialization of only three arrays it's almost full? Ifi crossed the RAM limit, would the IDE throw an error?
If i still need more RAM, can i use and external one with Due for high speed RAM acquisition?


user31105: 
A variable of uint16_t has 16 bits, thus two bytes, so for e.g. BuffA[46000] this means 46000 * 2 = 92000 bytes.
The variable all is also 16 bits and can contain only as max value 65,535. 
92000 + 40000 + 40000 = 172000 bytes but that does not fit in 16 bits.
Therefore the value is clipped ... make it a uint32_t variable.
The total is 172.000 bytes, this mean it will not fit in 96KB. What are the value ranges you want to store? If the values are max 255
You can use extra RAM. DRAM is very hard to use, EEPROM is only usable when you don't have to write it too often. Otherwise use SRAM, e.g. the 23LC1024's which can store 128 KB RAM and are only DIP8.


user3917: 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 report the number of elements, divide the total size by the number of bytes per element.  For example:
nElements = sizeof BuffA /  sizeof BuffA[0];

As uint16_t variables have 16 bits, the total all will exceed the maximum (65535) that all can hold.  Consider using uint32_t type for that variable. For example:
uint32_t all = sizeof BuffA/sizeof BuffA[0] + sizeof BuffB/sizeof BuffB[0] + sizeof BuffC/sizeof BuffC[0];

Because the type of sizeof is size_t, a “type able to represent the size of any object in bytes”, one need not cast any of addends to uint32_t for the result to not overflow.

user4143: 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 is because of integer wraparound. You only provide a 16-bit unsigned variable to store it in, so all you get is the lower 16 bits of the answer.
92000 + 40000 + 40000 = 172000

172000 in hex is 0x29FE0

0x29FE0 truncated to 16 bits is 0x9FE0

0x9FE0 in decimal is 40928.


The RAM of Due is 96kb. Does this mean that with the initialization of only three arrays it's almost full? Ifi crossed the RAM limit, would the IDE throw an error?

It would, but you aren't actually using the arrays for anything, so the compiler threw them away.

If i still need more RAM, can i use and external one with Due for high speed RAM acquisition?

There are ways of interfacing the SAM3X with external RAM, but I don't thing the Due exposes all the signals you need. I would change to a chip with more RAM, such as the PIC32MZ with 512kB of RAM and 200MHz operation.

1499: <p>I set out to see how much space some arrays have. I used this test code</p>

<pre><code>bool state = false;

uint16_t BuffA[46000];
uint16_t BuffB[20000];
uint16_t BuffC[20000];
uint16_t all = 0;

void setup(){
Serial.begin(9600);
}

void loop(){
if (state==false){
Serial.println(sizeof(BuffA));
Serial.println(sizeof(BuffB));
Serial.println(sizeof(BuffC));
all = sizeof(BuffA) + sizeof(BuffB) + sizeof(BuffC)
Serial.println(all);
state = true;
  }
}
</code></pre>

<p>I got this answer from the serial:</p>

<pre><code>92000
40000
40000
40928
</code></pre>

<ol>
<li>Why are the results doubled from those i initiated? Shouldn't the first one be 46kb and the other two 20kb?</li>
<li>Why is the last value only 40928?</li>
<li>The RAM of Due is 96kb. Does this mean that with the initialization of only three arrays it's almost full? Ifi crossed the RAM limit, would the IDE throw an error?</li>
<li>If i still need more RAM, can i use and external one with Due for high speed RAM acquisition?</li>
</ol>
 31105: <ol>
<li><p>A variable of uint16_t has 16 bits, thus two bytes, so for e.g. BuffA[46000] this means 46000 * 2 = 92000 bytes.</p></li>
<li><p>The variable all is also 16 bits and can contain only as max value 65,535. 
92000 + 40000 + 40000 = 172000 bytes but that does not fit in 16 bits.
Therefore the value is clipped ... make it a uint32_t variable.</p></li>
<li><p>The total is 172.000 bytes, this mean it will not fit in 96KB. What are the value ranges you want to store? If the values are max 255</p></li>
<li><p>You can use extra RAM. DRAM is very hard to use, EEPROM is only usable when you don't have to write it too often. Otherwise use SRAM, e.g. the 23LC1024's which can store 128 KB RAM and are only DIP8.</p></li>
</ol>
 3917: <p>The <a href="http://www.cplusplus.com/faq/sequences/arrays/sizeof-array/" rel="nofollow noreferrer"><code>sizeof</code></a> operator's result is <em>number of bytes</em>, not number of array elements.  Your arrays in the program above have two bytes per element, hence twice as many bytes as elements.</p>

<p>If you want to report the <em>number of elements</em>, divide the total size by the number of bytes per element.  For example:</p>

<pre><code>nElements = sizeof BuffA /  sizeof BuffA[0];
</code></pre>

<p>As <code>uint16_t</code> variables have 16 bits, the total <code>all</code> will exceed the maximum (65535) that <code>all</code> can hold.  Consider using <code>uint32_t</code> type for that variable. For example:</p>

<pre><code>uint32_t all = sizeof BuffA/sizeof BuffA[0] + sizeof BuffB/sizeof BuffB[0] + sizeof BuffC/sizeof BuffC[0];
</code></pre>

<p>Because the type of <code>sizeof</code> is <a href="http://www.cplusplus.com/reference/cstring/size_t/" rel="nofollow noreferrer"><code>size_t</code></a>, a “type able to represent the size of any object in bytes”, one need not cast any of addends to <code>uint32_t</code> for the result to not overflow.</p>
 4143: <p><code>sizeof</code> doesn't return the number of elements. It returns the number of <strong>bytes</strong>. Since they are <code>uint16_t</code> arrays each element is 2 bytes - hence twice the size.</p>

<p>The reason your last number is only 40928 is because of integer wraparound. You only provide a 16-bit unsigned variable to store it in, so all you get is the lower 16 bits of the answer.</p>

<pre><code>92000 + 40000 + 40000 = 172000

172000 in hex is 0x29FE0

0x29FE0 truncated to 16 bits is 0x9FE0

0x9FE0 in decimal is 40928.
</code></pre>

<blockquote>
  <p>The RAM of Due is 96kb. Does this mean that with the initialization of only three arrays it's almost full? Ifi crossed the RAM limit, would the IDE throw an error?</p>
</blockquote>

<p>It would, but you aren't actually using the arrays for anything, so the compiler threw them away.</p>

<blockquote>
  <p>If i still need more RAM, can i use and external one with Due for high speed RAM acquisition?</p>
</blockquote>

<p>There are ways of interfacing the SAM3X with external RAM, but I don't thing the Due exposes all the signals you need. I would change to a chip with more RAM, such as the PIC32MZ with 512kB of RAM and 200MHz operation.</p>
