Page 1 of 1

Heap problem.

Posted: Thu Aug 07, 2008 6:21 pm
by huxuelei
Hi , i wonder how to determine a proper start address and size of the heap in OS?

Re: Heap problem.

Posted: Thu Aug 07, 2008 10:02 pm
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:

Re: Heap problem.

Posted: Sat Aug 09, 2008 1:39 am
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?

Re: Heap problem.

Posted: Sun Aug 10, 2008 2:09 am
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