Is this write for unalloc?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Is this write for unalloc?

Post 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]
User avatar
deadmutex
Member
Member
Posts: 85
Joined: Wed Sep 28, 2005 11:00 pm

Re: Is this write for unalloc?

Post 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++;
	}
}
Da_Maestro
Member
Member
Posts: 144
Joined: Tue Oct 26, 2004 11:00 pm
Location: Australia

Re: Is this write for unalloc?

Post by Da_Maestro »

How are your pages allocated in the first place?
Two things are infinite: The universe and human stupidity. But I'm not quite sure about the universe.
--- Albert Einstein
Post Reply