Page 1 of 1

Is this write for unalloc?

Posted: Sun Jan 22, 2006 12:00 am
by earlz
I am making a unalloc for my memory manager so i needed a unset bit
so well i did this
I'm wondering if my unset bit and also my memory unallocation code is right
because according to my tests they are not

Code: Select all

void FreeCore(void *page_ptr,unsigned int num_pages){
		unsigned int index;unsigned int page=page_ptr;
	page=page/4096; //convert the address to a page number
	num_pages+=page;
	while(num_pages<page){
		index=page/32; //get what the index for pages is
		pages[index]=pages[index]&(0xFFFFFFFF^(1<<(page%32))); //CHECK HERE;unset the bit
		page++;
	}
}
[/code]

Re: Is this write for unalloc?

Posted: Mon Jan 23, 2006 12:00 am
by deadmutex
In your code, 'num_pages' will always be greater than or equal to 'page'(unless it overflows) because you added 'page' to 'num_pages'.

I think you meant:

Code: Select all

void FreeCore(void *page_ptr,unsigned int num_pages){
	unsigned int index;
        unsigned int start_page;
        unsigned int page=page_ptr;

	start_page=page=page/4096; //convert the address to a page number

	while(page < start_page + num_pages){
		index=page/32; //get what the index for pages is
		pages[index]=pages[index]&(0xFFFFFFFF^(1<<(page%32))); //CHECK HERE;unset the bit
		page++;
	}
}

Re: Is this write for unalloc?

Posted: Mon Jan 23, 2006 12:00 am
by Da_Maestro
How are your pages allocated in the first place?