This is meant to be a class that contains a 2d array of chars called "map". First, I allocate [mapDimension] char*s to a char**. Then, I allocate [mapDimension] chars to each char*. I do it this way rather than the static: char map[mapDimension][mapDimension] because while that works for small numbers, once mapDimension gets above around 2500, it also segfaults. I wanted to allocate the memory on the heap rather than the stack so that I could hold more.
The last two lines in the constructor are to initialize every char in the 2d array to 0 and then set the center one to 5.
#define mapDimension 1000    
class Field 
{
private:
    int i;
public:
    char** map = (char**)malloc(mapDimension * sizeof(char*));
    Field()
    {
        for(i = 0; i < mapDimension; i++)
            map[i] = (char*)malloc(mapDimension * sizeof(char));
        memset(map, 0, mapDimension*mapDimension*sizeof(char));
        map[mapDimension/2][mapDimension/2] = 5;
    }
};
int main()
{
    Field field;
    return 0;
}
This dynamic approach also segfaults. What am I doing wrong?
 
     
     
     
    