comparison vmalloc.c @ 81:a214c84dff4e

malloc_touch
author Merten Sach <msach@mailbox.tu-berlin.de>
date Mon, 11 Jul 2011 20:35:54 +0200
parents 97e26095c01f
children 21c95d402fe6
comparison
equal deleted inserted replaced
10:9a32e19e74f3 11:1fc17791b3e7
449 // thread's original stack available 449 // thread's original stack available
450 freeListHead = malloc( sizeof(MallocProlog) ); 450 freeListHead = malloc( sizeof(MallocProlog) );
451 firstChunk = malloc( MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE ); 451 firstChunk = malloc( MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE );
452 if( firstChunk == NULL ) {printf("malloc error\n"); exit(1);} 452 if( firstChunk == NULL ) {printf("malloc error\n"); exit(1);}
453 453
454 //Touch memory to avoid page faults 454 Touch memory to avoid page faults
455 //void *ptr,*endPtr; 455 void *ptr,*endPtr;
456 //endPtr = (void*)firstChunk+MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE; 456 endPtr = (void*)firstChunk+MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE;
457 //for(ptr = firstChunk; ptr < endPtr; ptr+=PAGE_SIZE) 457 for(ptr = firstChunk; ptr < endPtr; ptr+=PAGE_SIZE)
458 //{ 458 {
459 // *(char*)ptr = 0; 459 *(char*)ptr = 0;
460 //} 460 }
461 461
462 freeListHead->prevChunkInFreeList = NULL; 462 freeListHead->prevChunkInFreeList = NULL;
463 //Use this addr to free the heap when cleanup 463 //Use this addr to free the heap when cleanup
464 freeListHead->nextLowerInMem = firstChunk; 464 freeListHead->nextLowerInMem = firstChunk;
465 //to identify top-of-heap elem, compare this addr to elem's next higher 465 //to identify top-of-heap elem, compare this addr to elem's next higher