Need larger array size


I am developing a real-time motion controller for multiple DC motors. During my control loop I want to collect statistical data by saving it into an array, and then outputting the entire array to a file after the control loop is complete. My problem is that if I try to allocate my buffer array(float fBuffer[2000][6]) any larger than 2000, I get a memory fault (core dumped) error. Is there any way to make this array larger? I’ve tried allocating memory for the array using “new” command, but it doesn’t seem to let me allocate a 2-D array.

Any help would be great.


How do you allocated it. The array is 48k in size, that’s not a problem, unless you try to create in on the stack. The problem is probably when you try to access it and you are doing it wrong. Could you post some code.

As for new, it doesn’t care for that. I beleive the C language says pointer must be of at least 6 ( i think ) levels, so the language shoud support 6-D array.

typedef int mytype[2000];
mytype *variable = new mytype[6];

Shoud do the trick.

I am writing a fairly large object-oriented controller. I have summarized how I’ve used the array below.


#define QUEUE_SIZE 2000
class myBaseClass
virtual int myFunction(int)
return 0;

class myClass : public myBaseClass
float fBuffer[QUEUE_SIZE][6];
int myFunction(int iNumValues);


int myClass::myFunction(int iNumValues)
for (i=0;i<iNumValues;i++)
//Do stuff …

	//Store values in buffer array
 return 0;


//Main Program
#include “myClass.h”

int main()
myBaseClass *m;
myClass p;




Object p is instanciate on the stack, which means it using a good chunk of stack. Although 50k should not be a problem in your example, in a big program you might be running out of stack. That probably explains the crash.

Instead try

myClass *p = new myClass;

That will instanciate the object on the heap instead of on the help. You could also declare it static. Or have the fbuffer allocated dynamicaly.

In your example you have fbuffer[i][6]. Maybe it’s just related to your example here but fbuffer[0][6] is illegal, as [6] access the 7th element, which does not exists ;-)

Oops. The fbuffer[i][6] was just a mistake in my example. I don’t actually do that in the program. :slight_smile:

I will try declaring the fBuffer to be static, or allocate it dynamically.


Declaring the fbuffer static is not necessarely a good idea. That means every instances of myClass object will share the same fbuffer. It’s the myClass object that must be static not the fbuffer array.