質問編集履歴
3
ご指摘をもとに修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -335,3 +335,71 @@
|
|
335
335
|
```
|
336
336
|
|
337
337
|
に修正。
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
```C
|
342
|
+
|
343
|
+
for (int a = 0; a < BUF_SIZE; a++) {
|
344
|
+
|
345
|
+
char buffer[BUF_LENGTH] = "invalid";
|
346
|
+
|
347
|
+
cache[a] = &buffer[0];
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
```
|
352
|
+
|
353
|
+
を
|
354
|
+
|
355
|
+
```C
|
356
|
+
|
357
|
+
static char *cache[BUF_SIZE];
|
358
|
+
|
359
|
+
char invalid[8] = "invalid";
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
static char buffer1[BUF_LENGTH] = "invalid";
|
364
|
+
|
365
|
+
cache[0] = &buffer1[0];
|
366
|
+
|
367
|
+
static char buffer2[BUF_LENGTH] = "invalid";
|
368
|
+
|
369
|
+
cache[1] = &buffer2[0];
|
370
|
+
|
371
|
+
static char buffer3[BUF_LENGTH] = "invalid";
|
372
|
+
|
373
|
+
cache[2] = &buffer3[0];
|
374
|
+
|
375
|
+
static char buffer4[BUF_LENGTH] = "invalid";
|
376
|
+
|
377
|
+
cache[3] = &buffer4[0];
|
378
|
+
|
379
|
+
static char buffer5[BUF_LENGTH] = "invalid";
|
380
|
+
|
381
|
+
cache[4] = &buffer5[0];
|
382
|
+
|
383
|
+
static char buffer6[BUF_LENGTH] = "invalid";
|
384
|
+
|
385
|
+
cache[5] = &buffer6[0];
|
386
|
+
|
387
|
+
static char buffer7[BUF_LENGTH] = "invalid";
|
388
|
+
|
389
|
+
cache[6] = &buffer7[0];
|
390
|
+
|
391
|
+
static char buffer8[BUF_LENGTH] = "invalid";
|
392
|
+
|
393
|
+
cache[7] = &buffer8[0];
|
394
|
+
|
395
|
+
static char buffer9[BUF_LENGTH] = "invalid";
|
396
|
+
|
397
|
+
cache[8] = &buffer9[0];
|
398
|
+
|
399
|
+
static char buffer10[BUF_LENGTH] = "invalid";
|
400
|
+
|
401
|
+
cache[9] = &buffer10[0];
|
402
|
+
|
403
|
+
```
|
404
|
+
|
405
|
+
に書き下し。
|
2
頂いた指摘を元に改訂
test
CHANGED
File without changes
|
test
CHANGED
@@ -114,148 +114,182 @@
|
|
114
114
|
|
115
115
|
char invalid[8] = "invalid";
|
116
116
|
|
117
|
-
|
117
|
+
|
118
|
-
|
118
|
+
|
119
|
-
|
119
|
+
static char buffer1[BUF_LENGTH] = "invalid";
|
120
|
-
|
120
|
+
|
121
|
-
|
121
|
+
cache[0] = &buffer1[0];
|
122
|
+
|
123
|
+
static char buffer2[BUF_LENGTH] = "invalid";
|
124
|
+
|
125
|
+
cache[1] = &buffer2[0];
|
126
|
+
|
127
|
+
static char buffer3[BUF_LENGTH] = "invalid";
|
128
|
+
|
129
|
+
cache[2] = &buffer3[0];
|
130
|
+
|
131
|
+
static char buffer4[BUF_LENGTH] = "invalid";
|
132
|
+
|
133
|
+
cache[3] = &buffer4[0];
|
134
|
+
|
135
|
+
static char buffer5[BUF_LENGTH] = "invalid";
|
136
|
+
|
137
|
+
cache[4] = &buffer5[0];
|
138
|
+
|
139
|
+
static char buffer6[BUF_LENGTH] = "invalid";
|
140
|
+
|
141
|
+
cache[5] = &buffer6[0];
|
142
|
+
|
143
|
+
static char buffer7[BUF_LENGTH] = "invalid";
|
144
|
+
|
145
|
+
cache[6] = &buffer7[0];
|
146
|
+
|
147
|
+
static char buffer8[BUF_LENGTH] = "invalid";
|
148
|
+
|
149
|
+
cache[7] = &buffer8[0];
|
150
|
+
|
151
|
+
static char buffer9[BUF_LENGTH] = "invalid";
|
152
|
+
|
153
|
+
cache[8] = &buffer9[0];
|
154
|
+
|
155
|
+
static char buffer10[BUF_LENGTH] = "invalid";
|
156
|
+
|
157
|
+
cache[9] = &buffer10[0];
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
//print cache-----------------------------------------------------
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
for (int b = 0; b < BUF_SIZE; b++) {
|
166
|
+
|
167
|
+
printf("Cache[%d]: ", b);
|
168
|
+
|
169
|
+
for (int j = 0; j <INVALID_LENGTH ; ++j) {
|
170
|
+
|
171
|
+
printf("%c", *(cache[b] + j));
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
printf("\n");
|
122
176
|
|
123
177
|
}
|
124
178
|
|
125
|
-
|
126
|
-
|
127
|
-
|
179
|
+
printf("\n-------------------------------\n");
|
180
|
+
|
181
|
+
|
182
|
+
|
128
|
-
|
183
|
+
//ここでPutかGetかを判別する。
|
184
|
+
|
129
|
-
|
185
|
+
if ( *(uint16_t *)recvBuffer == 0x6262){//Put 0x6262==bb
|
186
|
+
|
187
|
+
|
188
|
+
|
130
|
-
|
189
|
+
//空いている場所を探す
|
190
|
+
|
191
|
+
printf("Putが実行\n");
|
192
|
+
|
193
|
+
printf("recvBuffer is: %s\n", recvBuffer);
|
194
|
+
|
195
|
+
int flag = 1;
|
196
|
+
|
131
|
-
for (int
|
197
|
+
for (int d = 0; d < BUF_SIZE; d++) {
|
132
|
-
|
198
|
+
|
133
|
-
|
199
|
+
//cache[d]がinvalidか照合
|
134
|
-
|
200
|
+
|
135
|
-
for (int j = 0; j <INVALID_LENGTH
|
201
|
+
for (int j = 0; j < INVALID_LENGTH; j++) {
|
202
|
+
|
136
|
-
|
203
|
+
if (*(cache[d] + j) != invalid[j]){
|
204
|
+
|
205
|
+
flag = 0;//cache[d]は空いている
|
206
|
+
|
137
|
-
printf("%c", *(cache[
|
207
|
+
printf("Cache[%d]の%cは%cと一致していない\n", d, *(cache[d]+j), invalid[j]);
|
138
|
-
|
208
|
+
|
139
|
-
}
|
209
|
+
}
|
210
|
+
|
140
|
-
|
211
|
+
}
|
212
|
+
|
213
|
+
//cache[d]がinvalidのとき→現状、1つでも一致すればよくなってしまっている
|
214
|
+
|
215
|
+
if (flag == 1) {
|
216
|
+
|
217
|
+
printf("Cache[%d]はinvalid!!\n", d);
|
218
|
+
|
219
|
+
cache[d] = recvBuffer; //[0]にはflagが入っているため
|
220
|
+
|
221
|
+
//無事キャッシュに格納完了
|
222
|
+
|
223
|
+
break;
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
//キャッシュが満杯の時、古いのを捨てる
|
230
|
+
|
231
|
+
if (flag == 0) {
|
232
|
+
|
233
|
+
printf("cache full----------------------------------\n");
|
234
|
+
|
235
|
+
cache[8] = recvBuffer; //適当に8番目を入れ替える
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
//
|
240
|
+
|
241
|
+
//キャッシュの中身を表示
|
242
|
+
|
243
|
+
printf("\n-------------------------------\n");
|
244
|
+
|
245
|
+
printf("new Cache is : \n");
|
246
|
+
|
247
|
+
for (int c = 0; c < BUF_SIZE; c++) {
|
248
|
+
|
249
|
+
printf("Cache[%d]: ", c);
|
250
|
+
|
251
|
+
for (int j = 0; j < INVALID_LENGTH; ++j) {
|
252
|
+
|
253
|
+
printf("%c", *(cache[c] + j));
|
254
|
+
|
255
|
+
}
|
256
|
+
|
141
|
-
printf("\n");
|
257
|
+
printf("\n");
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
return 0;//Putなので返すものはない
|
262
|
+
|
263
|
+
//-------------------------------------
|
264
|
+
|
265
|
+
} else if(*(uint16_t *)recvBuffer == 0x6161){ //Getのとき 0x6161==aa
|
266
|
+
|
267
|
+
printf("Getが実行\n");
|
268
|
+
|
269
|
+
for (int i = 0; i < BUF_SIZE; i++) {
|
270
|
+
|
271
|
+
if (recvBuffer[i+1] == *cache[i]) {
|
272
|
+
|
273
|
+
printf("Cache Hit!");
|
274
|
+
|
275
|
+
return 1; //Cache hitのときは1を返すようにする
|
276
|
+
|
277
|
+
break;
|
278
|
+
|
279
|
+
//sendBuffer_fromserver[0] = '1';
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
//for文が最後まで実装されたらキャッシュミス
|
286
|
+
|
287
|
+
printf("Cache Miss!\n");
|
288
|
+
|
289
|
+
return 2; //cache miss のときは2を返すようにする
|
142
290
|
|
143
291
|
}
|
144
292
|
|
145
|
-
printf("\n-------------------------------\n");
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
//ここでPutかGetかを判別する。
|
150
|
-
|
151
|
-
if ( *(uint16_t *)recvBuffer == 0x6262){//Put 0x6262==bb
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
//空いている場所を探す
|
156
|
-
|
157
|
-
printf("Putが実行\n");
|
158
|
-
|
159
|
-
printf("recvBuffer is: %s\n", recvBuffer);
|
160
|
-
|
161
|
-
int flag = 1;
|
162
|
-
|
163
|
-
for (int d = 0; d < BUF_SIZE; d++) {
|
164
|
-
|
165
|
-
//cache[d]がinvalidか照合
|
166
|
-
|
167
|
-
for (int j = 0; j < INVALID_LENGTH; j++) {
|
168
|
-
|
169
|
-
if (*(cache[d] + j) != invalid[j]){
|
170
|
-
|
171
|
-
flag = 0;//cache[d]は空いている
|
172
|
-
|
173
|
-
printf("Cache[%d]の%cは%cと一致していない\n", d, *(cache[d]+j), invalid[j]);
|
174
|
-
|
175
|
-
}
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
//cache[d]がinvalidのとき→現状、1つでも一致すればよくなってしまっている
|
180
|
-
|
181
|
-
if (flag == 1) {
|
182
|
-
|
183
|
-
printf("Cache[%d]はinvalid!!\n", d);
|
184
|
-
|
185
|
-
cache[d] = recvBuffer; //[0]にはflagが入っているため
|
186
|
-
|
187
|
-
//無事キャッシュに格納完了
|
188
|
-
|
189
|
-
break;
|
190
|
-
|
191
|
-
}
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
//キャッシュが満杯の時、古いのを捨てる
|
196
|
-
|
197
|
-
if (flag == 0) {
|
198
|
-
|
199
|
-
printf("cache full----------------------------------\n");
|
200
|
-
|
201
|
-
cache[8] = recvBuffer; //適当に8番目を入れ替える
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
//
|
206
|
-
|
207
|
-
//キャッシュの中身を表示
|
208
|
-
|
209
|
-
printf("\n-------------------------------\n");
|
210
|
-
|
211
|
-
printf("new Cache is : \n");
|
212
|
-
|
213
|
-
for (int c = 0; c < BUF_SIZE; c++) {
|
214
|
-
|
215
|
-
printf("Cache[%d]: ", c);
|
216
|
-
|
217
|
-
for (int j = 0; j < INVALID_LENGTH; ++j) {
|
218
|
-
|
219
|
-
printf("%c", *(cache[c] + j));
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
printf("\n");
|
224
|
-
|
225
|
-
}
|
226
|
-
|
227
|
-
return 0;//Putなので返すものはない
|
228
|
-
|
229
|
-
//-------------------------------------
|
230
|
-
|
231
|
-
} else if(*(uint16_t *)recvBuffer == 0x6161){ //Getのとき 0x6161==aa
|
232
|
-
|
233
|
-
printf("Getが実行\n");
|
234
|
-
|
235
|
-
for (int i = 0; i < BUF_SIZE; i++) {
|
236
|
-
|
237
|
-
if (recvBuffer[i+1] == *cache[i]) {
|
238
|
-
|
239
|
-
printf("Cache Hit!");
|
240
|
-
|
241
|
-
return 1; //Cache hitのときは1を返すようにする
|
242
|
-
|
243
|
-
break;
|
244
|
-
|
245
|
-
//sendBuffer_fromserver[0] = '1';
|
246
|
-
|
247
|
-
}
|
248
|
-
|
249
|
-
}
|
250
|
-
|
251
|
-
//for文が最後まで実装されたらキャッシュミス
|
252
|
-
|
253
|
-
printf("Cache Miss!\n");
|
254
|
-
|
255
|
-
return 2; //cache miss のときは2を返すようにする
|
256
|
-
|
257
|
-
}
|
258
|
-
|
259
293
|
}
|
260
294
|
|
261
295
|
```
|
1
char *cache[BUF_SIZE]; を static char *cache[BUF_SIZE]; に修正。なお問題は解決せず。
test
CHANGED
File without changes
|
test
CHANGED
@@ -110,7 +110,7 @@
|
|
110
110
|
|
111
111
|
//cache definition--------------------------------------------------
|
112
112
|
|
113
|
-
char *cache[BUF_SIZE];
|
113
|
+
static char *cache[BUF_SIZE];
|
114
114
|
|
115
115
|
char invalid[8] = "invalid";
|
116
116
|
|
@@ -277,3 +277,27 @@
|
|
277
277
|
|
278
278
|
|
279
279
|
どなたか解決策を思いつく方ご教授頂けると幸いです。
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
----------------------------------------------------------------
|
284
|
+
|
285
|
+
現在の進捗
|
286
|
+
|
287
|
+
----------------------------------------------------------------
|
288
|
+
|
289
|
+
```C
|
290
|
+
|
291
|
+
char *cache[BUF_SIZE];
|
292
|
+
|
293
|
+
```
|
294
|
+
|
295
|
+
を
|
296
|
+
|
297
|
+
```C
|
298
|
+
|
299
|
+
static char *cache[BUF_SIZE];
|
300
|
+
|
301
|
+
```
|
302
|
+
|
303
|
+
に修正。
|