Am I getting out of memory here?(dynamic matrix related)

Hi, My code works properly but ends in one point without any warning. Here the code below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#include <iostream>
#include <array>
#include <vector>

std::vector< std::array<int, 8> > possVec;
std::vector< std::array<int, 8> > checkedVec;
std::array< int , 8> tempArr;
int row, col, depth, sameCount;

// kýrmýzý: 1 ; mavi: 2 ; yeþil: 3 ;

int *** flipX(int x, int y, int *** kupX)
{
    //

    if( x < y && y != 0 )
    {
        //store kupX in temp 3d array
        //flipX temp 3d array
        // recurs flipX(x + 1, y, temp 3d array);
        int *** tempKup = new int ** [2];

        for( int i = 0; i < 2; i++ )
        {
            //
            //int * tempKup = new int [2];
            tempKup[i] = new int * [2];
            for( int j = 0; j < 2; j++ )
            {
                //
                tempKup[i][j] = new int [2];
            }
        }

        for( int i = 0; i < 2; i++ )
        {
            //
            for( int j = 0; j < 2; j++ )
            {
                //
                for( int k = 0; k < 2; k++ )
                {
                    //
                    tempKup[i][j][k] = kupX[i][j][k];

                }
            }
        }

        tempKup[0][0][1] = kupX[0][0][0];
        tempKup[0][1][1] = kupX[0][1][0];
        tempKup[1][0][1] = kupX[0][0][1];
        tempKup[1][1][1] = kupX[0][1][1];
        tempKup[1][0][0] = kupX[1][0][1];
        tempKup[1][1][0] = kupX[1][1][1];
        tempKup[0][0][0] = kupX[1][0][0];
        tempKup[0][1][0] = kupX[1][1][0];

        if( x == y )
        {
            //
            return tempKup;
        }
        else
        {
            //
            flipX(x + 1, y, tempKup);
        }

    // if memory for arrays is limited delete local arrays

    }
    else if( y == 0 )
    {
        //
        return kupX;
    }
    else if( x == y && y != 0 )
    {
        //
        return kupX;
    }

}

int*** flipY( int x, int y, int *** kupX )
{
    //
    if( x < y && y != 0 )
    {
        //store kupX in temp 3d array
        //flipX temp 3d array
        // recurs flipX(x + 1, y, temp 3d array);
        int *** tempKup = new int ** [2];

        for( int i = 0; i < 2; i++ )
        {
            //
            //int * tempKup = new int [2];
            tempKup[i] = new int * [2];
            for( int j = 0; j < 2; j++ )
            {
                //
                tempKup[i][j] = new int [2];
            }
        }

        for( int i = 0; i < 2; i++ )
        {
            //
            for( int j = 0; j < 2; j++ )
            {
                //
                for( int k = 0; k < 2; k++ )
                {
                    //
                    tempKup[i][j][k] = kupX[i][j][k];

                }
            }
        }

        tempKup[0][0][1] = kupX[0][1][1];
        tempKup[0][1][1] = kupX[1][1][1];
        tempKup[1][0][1] = kupX[0][0][1];
        tempKup[1][1][1] = kupX[1][0][1];
        tempKup[1][0][0] = kupX[0][0][0];
        tempKup[1][1][0] = kupX[1][0][0];
        tempKup[0][0][0] = kupX[0][1][0];
        tempKup[0][1][0] = kupX[1][1][0];

        if( x == y )
        {
            //
            return tempKup;
        }
        else
        {
            //
            flipY(x + 1, y, tempKup);
        }


    // if memory for arrays is limited delete local arrays

    }
    else if( y == 0 )
    {
        //
        return kupX;
    }
    else if( x == y && y != 0 )
    {
        //
        return kupX;
    }

}

void fillPossVec(int x, int y)
{
    //
    if( x < y )
    {
        //
        for( int i = 1; i <= 3; i++ )
        {
            //
            tempArr[x] = i;
            fillPossVec(x + 1, y);

        }
    }
    else
    {
        //
        possVec.push_back(tempArr);
    }

}

int *** createKupFromVec(int x, std::vector< std::array<int, 8> > Vec)
{
    //
    row = 0;
    col = 0;
    depth = 0;

    int *** kup = new int ** [2];

    for( int i = 0; i < 2; i++ )
    {
        //
        //int * tempKup = new int [2];
        kup[i] = new int * [2];
        for( int j = 0; j < 2; j++ )
        {
            //
            kup[i][j] = new int [2];
        }
    }

    for( int i = 0; i < 8; i++ )
    {
        //
        if( i % 4 == 0 && i != 0)
        {
            //
            row += 1;
            col = 0;
        }
        if( i % 4 != 0 && i % 2 == 0 )
        {
            //
            col += 1;
        }


        kup[row][col][i%2] = Vec[x][i];
    }

    return kup;

}

int checkKups(int *** arrX , int *** arrY)
{
    //returns 1 if same, 0 if not
    for( int i = 0; i < 2; i++ )
    {
        //
        for( int j = 0; j < 2; j++ )
        {
            //
            for( int k = 0; k < 2; k++ )
            {
                //
                if( arrX[i][j][k] != arrY[i][j][k] )
                {
                    //
                    return 0;
                }
            }

        }
    }
    return 1;
}


void fullControl()
{
    //
    for( int i = 0; i < possVec.size(); i++ )
    {
        //
        if( i == 0 )
        {
            //
            checkedVec.push_back(possVec[i]);
        }
        else
        {
            //
            sameCount = 0;
            for( int j = 0; j < checkedVec.size(); j++ )
            {
                //
                for( int xflip = 0; xflip <= 3; xflip ++ )
                {
                    //
                    for( int yflip = 0; yflip <= 3; yflip++ )
                    {
                        //
                        if( checkKups(createKupFromVec(j, checkedVec), flipX(0, xflip, flipY(0, yflip, createKupFromVec(i, possVec)))) == 1 )
                        {
                            //
                            sameCount += 1;
                        }

                    }

                }

            }
            if( sameCount == 0 && i != 0 )
            {
                //
                checkedVec.push_back(possVec[i]);
                std::cout << checkedVec.size() << std::endl;
            }
        }

    }

}

int main()
{

    fillPossVec(0 , 8);
    fullControl();
    std::cout << checkedVec.size();

    return 0;
}


Do you think the reason is the declaration of too many int *** 's or anything else? If so, what to do? I can not delete the int ***'s becase I am returning them in another function. Thanks.
Last edited on
> Am I getting out of memory here?
considering that there is not a single delete, that may be the case

> I can not delete the int ***'s becase I am returning them in another function.
¿why can't you use std::vector? or std::array, as the dimensions are constants.
Topic archived. No new replies allowed.