Skip to content

Instantly share code, notes, and snippets.

@jwendell
Created June 13, 2018 10:41
Show Gist options
  • Save jwendell/0e22fb0b18efaf696ba46eca83cc9f0f to your computer and use it in GitHub Desktop.
Save jwendell/0e22fb0b18efaf696ba46eca83cc9f0f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
if (argc != 2) {
fprintf(stderr, "Usage: %s <MEM SIZE>\n", argv[0]);
return 1;
}
printf("Allocating %s bytes of memory...\n", argv[1]);
int size = atoi(argv[1]);
char *mem = calloc(size, 1);
printf("Allocated successfuly %p\n", mem);
printf("Using that memory...\n");
for (int i=0; i < size; i++)
mem[i] = (i % 254) + 1;
printf("Success.\n");
printf("Freeing memory...\n");
free(mem);
printf("Success.\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment