mirror of
https://github.com/SmallPond/MIT6.828_OS.git
synced 2026-04-29 13:21:17 +08:00
my solution to lab5
This commit is contained in:
24
lab/user/testmalloc.c
Normal file
24
lab/user/testmalloc.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <inc/lib.h>
|
||||
|
||||
void
|
||||
umain(int argc, char **argv)
|
||||
{
|
||||
char *buf;
|
||||
int n;
|
||||
void *v;
|
||||
|
||||
while (1) {
|
||||
buf = readline("> ");
|
||||
if (buf == 0)
|
||||
exit();
|
||||
if (memcmp(buf, "free ", 5) == 0) {
|
||||
v = (void*) strtol(buf + 5, 0, 0);
|
||||
free(v);
|
||||
} else if (memcmp(buf, "malloc ", 7) == 0) {
|
||||
n = strtol(buf + 7, 0, 0);
|
||||
v = malloc(n);
|
||||
printf("\t0x%x\n", (uintptr_t) v);
|
||||
} else
|
||||
printf("?unknown command\n");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user