Finished FastBin/CaNaKMgF_remastered

This commit is contained in:
2024-10-24 20:56:26 +08:00
committed by GitHub
parent 5537ec2174
commit 9e61260765
3 changed files with 101 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
char* alloc_list[100];
unsigned int alloc_idx = 0;
int main() {
unsigned int option, size, index;
while (1) {
scanf("%u", &option);
switch (option) {
case 1: { // allocate(size, data)
scanf("%u", &size);
char *buf = malloc(size);
read(0, buf, size);
alloc_list[alloc_idx++] = buf;
break;
}
case 3: { // free(index)
scanf("%u", &index);
free(alloc_list[index]);
// alloc_list[index] is a
// dangling pointer now
break;
}
case 4: { // read(index)
scanf("%u", &index);
puts(alloc_list[index]);
break;
}
}
}
}