Question: Does doing something like this use dynamic memory allocation?

```
template <class T, int _size> 
class CArray 
{ 
public:
    ... 
private:
    T m_data[_size]; 
};

```

Can someone explain to me what's going on behind the scenes when I create the object?

```
CArray<SomeObject, 32> myStupidArray;

```

Answer: 
As mentioned in the other answers, templates are evaluated at compile time. If you're interested you can have g++ spit out the class hierarchy where you can verify its size:

```
template <class T, int _size>
class CArray
{
public:
private:
  T m_data[_size];
};

int main(int argc, char **argv) {
  CArray<int, 32> myStupidArray1;
  CArray<int, 8> myStupidArray2;
  CArray<int, 64> myStupidArray3;
  CArray<int, 1000> myStupidArray4;
}

```

Compile with `-fdump-class-hierarchy`:

```
g++ -fdump-class-hierarchy blah.cc

```

There should be a file named `blah.cc.t01.class` in the current directory:

```
Class CArray<int, 32>
   size=128 align=4
   base size=128 base align=4
CArray<int, 32> (0x40be0d80) 0

Class CArray<int, 8>
   size=32 align=4
   base size=32 base align=4
CArray<int, 8> (0x40be0e80) 0

Class CArray<int, 64>
   size=256 align=4
   base size=256 base align=4
CArray<int, 64> (0x40be0f80) 0

Class CArray<int, 1000>
   size=4000 align=4
   base size=4000 base align=4
CArray<int, 1000> (0x40be6000) 0

```
The size of the array is known at compile time, so no, it won't be using dynamic memory allocation here. If you declare the array in a function scope then it'll be put on the stack just like any other type of object.

When you define variable-sized objects like this, what's really happening is that the compiler is building a class definition 'to order'. You'll just be using a class definition that contains 'T m\_data[32]' in it.