Skip to content

Commit

Permalink
replaced old function with malloc_two()
Browse files Browse the repository at this point in the history
  • Loading branch information
b3h3moth committed Feb 29, 2016
1 parent 09cc78c commit 13ab907
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions Memory_Allocation/malloc_implementations/malloc_two/main.c
@@ -1,33 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "basic_malloc.h"
#include "xmalloc.h"
#include "zmalloc.h"
#include "malloc_two.h"

int main(void) {
const char *title = "The Unix Programming Environment";
const unsigned int size = strlen(title);
char *ptr;

// basic_malloc() testing function
// Alloca 'size' byte sullo heap, dopodiche' copia e stampa la stringa
ptr = basic_malloc(size);
strcpy(ptr, title);
printf("%s\n", ptr);

/* Con la prima funzione per l'allocazione della memoria basic_malloc(),
non puo' essere invocata free() per liberare la memoria, per cui si
utilizza' un semplice puntatore a NULL, che peraltro dovrebbe essere una
buona regola dopo la deallocazione della memoria. */
ptr = NULL;

// xmalloc() testing function
char *ptr2;
ptr2 = xmalloc(size);
strncpy(ptr2, title, strlen(title)+1);
printf("%s\n", ptr2);
xfree(ptr2);
char *ptr;
ptr = malloc_two(size);
strncpy(ptr, title, strlen(title)+1);
printf("%s\n", ptr);
free_two(ptr);

return(EXIT_SUCCESS);
}

0 comments on commit 13ab907

Please sign in to comment.