diff options
Diffstat (limited to 'riscv/riscv-probe/examples/malloc/main.c')
| -rw-r--r-- | riscv/riscv-probe/examples/malloc/main.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/riscv/riscv-probe/examples/malloc/main.c b/riscv/riscv-probe/examples/malloc/main.c new file mode 100644 index 0000000..cde2038 --- /dev/null +++ b/riscv/riscv-probe/examples/malloc/main.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main(int argc, char **argv) +{ + const size_t nelems = 8; + const size_t elemsize = 128; + char *alloc[nelems]; + + for (size_t i = 0; i < nelems; i++) { + if (alloc[i] = malloc(elemsize)) { + memset(alloc[i], 0, elemsize); + } + printf("malloc[%d]=0x%x\n", i, alloc[i]); + } + + for (size_t i = 0; i < nelems; i++) { + free(alloc[i]); + } +}
\ No newline at end of file |
