Array initialisation in a class

Hello forum, I was trying to write a quick and dirty ring buffer and have run into the following problem, I 'm not too sure what happens when I try to declare an array as a member of a class but initialise it in a constructor, e.g.

class myRingBuffer {

int daBuffer[];

myRingBuffer(int size) {

void setup() {
myRingBuffer mrb = myRingBuffer(10);
mrb.daBuffer[9] = 3;

void loop() {


So, the above compiles, uploads and prints 3 on the serial monitor. But is it doing what I assume it is doing, that is creating a 10 integer long array when the constructor gets called? Or does the single line in the constructor simply call an address "size" integers down from the start of the array and discard the result? What I 'm driving at is, when I read/write to the array after I instantiate "mrb" am I using a legal address or am I groping at random somewhere in memory?

One final worry, when trying to encapsulate stuff to keep things tidy, is there any worthwhile performance difference if using typedef and data structures instead of C++ classes?

You can use template programming for solving this:

The for-loop in the ‘setup’ fucntion of that HelloSimpleFIFO.pde example will not produce the results you’re probably expecting and should probably replaced with a while-loop as follows:

void setup() {
  SimpleFIFO<int,10> sFIFO; //store 10 ints
  Serial.print("Peek: ");
  while ( sFIFO.count() ) {
    Serial.print("Dequeue ");

Thanks guys, I 'll check out FIFO. However, can you let me know if the code I posted does what I thought it does or if it's a horrible monstrosity?