Skip to content

Commit 5633f56

Browse files
author
alielabridi
committed
saving array to try to play with message with vectors
1 parent 8d6dd44 commit 5633f56

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

ValueMsg.h

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,33 @@
33

44
class ValueMsg : public CMessage_ValueMsg {
55
public:
6-
std::vector<std::vector<int> > v;
6+
int** v;
77
//i found a solution to allocate a non fixed sized without segment fault
8-
ValueMsg(int size):v(size, std::vector<int>(size)){}
9-
ValueMsg(){}
8+
ValueMsg(int size){
9+
v = new int*[size];
10+
for (int i = 0; i < size; ++i){
11+
v[i] = new int[size];
12+
}
1013

14+
15+
}
1116
//for the time being i am going to stick to array as vectors produce segment fault
1217
//int v[4][4];
1318
};
1419

1520

1621
class AddSubMsg : public CMessage_AddSubMsg {
1722
public:
18-
std::vector<std::vector<int> > A;
19-
std::vector<std::vector<int> > B;
23+
int** A;
24+
int** B;
2025
//i found a solution to allocate a non fixed sized without segment fault
21-
AddSubMsg(){}
2226
AddSubMsg(int size){
23-
A = std::vector<std::vector<int>> (size,std::vector<int>(size));
24-
B = std::vector<std::vector<int>> (size,std::vector<int>(size));
27+
A = new int*[size];
28+
B = new int*[size];
29+
for (int i = 0; i < size; ++i){
30+
A[i] = new int[size];
31+
B[i] = new int[size];
32+
}
2533
}
2634

2735
//for the time being i am going to stick to array as vectors produce segment fault
@@ -31,13 +39,16 @@ class AddSubMsg : public CMessage_AddSubMsg {
3139

3240
class StrassenMsg : public CMessage_StrassenMsg {
3341
public:
34-
std::vector<std::vector<int> > A;
35-
std::vector<std::vector<int> > B;
42+
int** A;
43+
int** B;
3644
//i found a solution to allocate a non fixed sized without segment fault
37-
StrassenMsg(){}
3845
StrassenMsg(int size){
39-
A = std::vector<std::vector<int>> (size,std::vector<int>(size));
40-
B = std::vector<std::vector<int>> (size,std::vector<int>(size));
46+
A = new int*[size];
47+
B = new int*[size];
48+
for (int i = 0; i < size; ++i){
49+
A[i] = new int[size];
50+
B[i] = new int[size];
51+
}
4152
}
4253

4354
//for the time being i am going to stick to array as vectors produce segment fault
@@ -47,18 +58,23 @@ class StrassenMsg : public CMessage_StrassenMsg {
4758

4859
class StrassenSubMsg : public CMessage_StrassenSubMsg {
4960
public:
50-
std::vector<std::vector<int> > A;
51-
std::vector<std::vector<int> > B;
52-
std::vector<std::vector<int> > C;
53-
std::vector<std::vector<int> > D;
61+
int** A;
62+
int** B;
63+
int** C;
64+
int** D;
5465
//i found a solution to allocate a non fixed sized without segment fault
55-
StrassenSubMsg(){}
5666

5767
StrassenSubMsg(int size){
58-
A = std::vector<std::vector<int>> (size,std::vector<int>(size));
59-
B = std::vector<std::vector<int>> (size,std::vector<int>(size));
60-
C = std::vector<std::vector<int>> (size,std::vector<int>(size));
61-
D = std::vector<std::vector<int>> (size,std::vector<int>(size));
68+
A = new int*[size];
69+
B = new int*[size];
70+
C = new int*[size];
71+
D = new int*[size];
72+
for (int i = 0; i < size; ++i){
73+
A[i] = new int[size];
74+
B[i] = new int[size];
75+
C[i] = new int[size];
76+
D[i] = new int[size];
77+
}
6278
}
6379

6480
//for the time being i am going to stick to array as vectors produce segment fault

0 commit comments

Comments
 (0)