Exemplo n.º 1
0
int main()
{
    char ch1[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; 
    //memmove(ch1 + 1, ch1 +3, 9);
    memmove(ch1 + 4, ch1, 3);

    char ch2[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; 
    //my_memmove(ch2 + 1, ch2 +3, 9);
    my_memmove(ch2 + 4, ch2, 3);
    
    getchar();
    return 0;
}
Exemplo n.º 2
0
int main()
{
  vecteur v1,v2;
  int taille;

  v1 = lit_vecteur("vecteur1.txt");
  affiche_vecteur(v1);
  taille = taille_vecteur(v1);
  v2 = allouer_vecteur(taille);
  my_memcpy(acces_vecteur(v2,0), acces_vecteur(v1,0),taille*sizeof(double));
  my_memmove(acces_vecteur(v2,0), acces_vecteur(v2,taille/4), (taille/2)*sizeof(double));
  affiche_vecteur(v2);
  my_memcpy(acces_vecteur(v2,0), acces_vecteur(v1,0),taille*sizeof(double));
  my_memmove(acces_vecteur(v2,taille/4), acces_vecteur(v2,0), (taille/2)*sizeof(double));
  affiche_vecteur(v2);
  liberer_vecteur(v1);
  liberer_vecteur(v2);

  printf("Difference malloc/free : %d\n",malloc_counter - free_counter);
  
  return 0;
}
Exemplo n.º 3
0
int testMemmove(size_t SIZE)
{
	int i,rv,j;
	char * src=getBuffer(SIZE+1);
	char * dst=calloc(SIZE+1,sizeof(char));

	printf("testSize:%i\n",SIZE);
	my_memmove(dst,src,SIZE);
	rv=differ(dst,src,SIZE) ;
	if ( rv ) printf("Error 1\n");

	free(src);
	free(dst);
	return 0;
}
Exemplo n.º 4
0
int testMemmoveAlign(size_t SIZE)
{
	int rv,j;
	for ( j=1;j<SIZE;++j)
	{
		char *src=getBuffer(SIZE+1);
		char *ref=getBuffer(SIZE+1);

		printf("testAlign:%p,%p,%i,%i\n",src+j,src,SIZE-j,j);
		my_memmove(src+j, src, SIZE-j);

		rv=differ( src+j, src,min(j,SIZE-j)) ;
		if ( rv ) printf("Error 2\n----------------------------------------\n");

		rv=differ( src+j, ref,SIZE-j) ;
		if ( rv ) printf("Error 3\n----------------------------------------\n");
		free(src);
		free(ref);
		printf("\n");
	}
}
Exemplo n.º 5
0
static void* my_memmove_fast(void* _src, void* _dest, size_t amount)
{
	unsigned long long *src = _src;
	unsigned long long *dest = _dest;
	
	/* standard says (I think) guaranteed to be AT LEAST 64 bit */
	size_t longsize = sizeof(unsigned long long);
	
	if(src == dest)
		return dest;
	
	if( dest > src) {
		while(amount >= longsize) {
			*dest = *src;
			dest--;
			src--;
			amount -= longsize;
		}
	}
	else{
		while(amount >= longsize) {
			*dest = *src;
			dest++;
			src++;
			amount -= longsize;
		}
	}	
	

	/* clean up if cpy amount was not % 64 bit */
	/* inline me! */
	if(amount > 0){
		my_memmove(src,dest,amount);
	}
	return _dest;
}
Exemplo n.º 6
0
int main() {
// Test my_malloc, my_free normal conditions
int *a = my_malloc(4);
*a = 5;
assert(*a = 5);
//assert_freelist_count(8,0,0,0,0,0,0,1,0);
printf("--------------------\n");
assert_freelist_count(8, 0, 1, 1, 1, 1, 1, 1, 0);
printf("Passed the first test-\n");

int *b = my_malloc(490);
*b = 1;
assert_freelist_count(8, 0, 0, 1, 1, 1, 1, 1, 0);
printf("Passed the second test-\n");


int *c = my_malloc(490);
*c = 1;
assert_freelist_count(8, 0, 1, 1, 1, 1, 1, 1, 0);
printf("Passed the third test-\n");


int *d = my_malloc(200);
assert(ERRNO == NO_ERROR);
*d = 1;
assert_freelist_count(8, 0, 1, 1, 0, 1, 1, 1, 0);
printf("Passed the fourth test-\n");


int *e = my_malloc(490);
*e = 1;
assert_freelist_count(8, 0, 0, 1, 0, 1, 1, 1, 0);
printf("Passed the fifth test-\n");



my_free(a);
assert_freelist_count(8, 0, 0, 1, 1, 0, 0, 0, 0);
printf("Passed the first free test-\n");


my_free(b);
assert_freelist_count(8, 0, 1, 1, 1, 0, 0, 0, 0);
printf("Passed the second free test-\n");

my_free(c);
assert_freelist_count(8, 0, 2, 1, 1, 0, 0, 0, 0);
printf("Passed the third free test\n");

my_free(d);
assert_freelist_count(8, 1, 1, 0, 0, 0, 0, 0, 0);
printf("Passed the fourth free test \n");

my_free(e);

assert(ERRNO == NO_ERROR);
assert_freelist_count(8, 2, 0, 0, 0, 0, 0, 0, 0);
printf("Passed the fifth free test \n");

fprintf(stderr, "%s\n", "--- PASSED MY_MALLOC, MY_FREE NORMAL CONDITIONS ---");
// Test my_malloc SINGLE_REQUEST_TOO_LARGE
assert(my_malloc(2049) == NULL);
assert(ERRNO == SINGLE_REQUEST_TOO_LARGE);
fprintf(stderr, "%s\n", "--- PASSED MY_MALLOC, SINGLE_REQUEST_TOO_LARGE ---");
// Test my_malloc extending heap size
int *f = my_malloc(2000);
*f = 5;
int *g = my_malloc(2000);
*g = 12;
int *h = my_malloc(2000);
*h = 13;
int *i = my_malloc(2000);
*i = 32;
assert(ERRNO == NO_ERROR);
// Test my_malloc OUT_OF_MEMORY
assert(my_malloc(1990) == NULL);
assert(ERRNO == OUT_OF_MEMORY);
my_free(f);
my_free(g);
my_free(h);
my_free(i);
assert_freelist_count(8, 4, 0, 0, 0, 0, 0, 0, 0);
fprintf(stderr, "%s\n", "--- PASSED MY_MALLOC, OUT_OF_MEMORY ---");
// Test my_free, DOUBLE_FREE_DETECTED
my_free(a);
//assert(ERRNO == DOUBLE_FREE_DETECTED);
fprintf(stderr, "%s\n", "--- PASSED MY_FREE, DOUBLE_FREE_DETECTED ---");
// Test my_memmove
char* string1 = my_malloc(20);
char* string2 = my_malloc(20);
string1 = "test";
my_memmove(string2, string1, 4);
assert(strcmp(string2, string1) == 0);
my_memmove((char *)string2 + 1, string1, 4);
assert(strcmp(string2, "ttest") == 0);
my_memmove((char *)string2 + 1, string2, 4);
assert(strcmp(string2, "tttes") == 0);
fprintf(stderr, "%s\n", "--- PASSED MY_MEMMOVE ---");
// Test my_calloc
char* calloc1 = my_calloc(2, 16);
assert(zeroed_out(calloc1, 32) == 1);
assert(ERRNO == NO_ERROR);
char* calloc2 = my_calloc(20, 300);
assert(calloc2 == NULL);
assert(ERRNO == SINGLE_REQUEST_TOO_LARGE);
fprintf(stderr, "%s\n", "--- PASSED MY_CALLOC ---");
return 0;
}