Heap problem.

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
huxuelei
Member
Member
Posts: 35
Joined: Tue May 27, 2008 8:32 am

Heap problem.

Post by huxuelei »

Hi , i wonder how to determine a proper start address and size of the heap in OS?
eddyb
Member
Member
Posts: 248
Joined: Fri Aug 01, 2008 7:52 am

Re: Heap problem.

Post by eddyb »

the start address can be token from end pointer. if is defined in your linker script, it points to the end of the kernel.
put _end; at the end of you linker definitions, and you can use it by

Code: Select all

extern int end;
int heap_start = (int)&end;
the heap size.... just set to some common value, let's say the size of a page(4KB). if you need to expand(no more space), just alloc a new page and add to the size of the heap 4KB. when you'll contract(more free space at end of the heap than 4KB), free some pages and subtract to the size of the heap no_pages_freed*4KB(be aware, don't free all your heap ;))

so you are done with this. :mrgreen:
huxuelei
Member
Member
Posts: 35
Joined: Tue May 27, 2008 8:32 am

Re: Heap problem.

Post by huxuelei »

Hi, I am not fully understand.If i just use the kernel's end address as the start address of the heap, I think it's possible the heap will overlap with the page directory and page table in the system.

So here is a question, is there any proper way to decide the range of the kernel space, page directory space, page table space, heap space and stack space?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Heap problem.

Post by AJ »

Short answer: No.

It's really up to you - there is no structure to the memory until your kernel puts it in place. What are your design goals and kernel model?

Cheers,
Adam
Post Reply