Page 1 of 1

Memory allocator = done, memory management = ?

Posted: Thu Nov 27, 2008 5:34 am
by leledumbo
I've implemented memory allocators both physical and virtual as in tutorial 17 & 18 (with a "little" modification, of course). The question is, how do I manage them? I mean, if I have a function like:

Code: Select all

function GetMem(Size: LongWord): Pointer;
how do I connect it with AllocPage (corresponds to your vmmngr_alloc_page)? Plus, if I allocate more than one page, AFAIK they have to be contiguous. How can I ensure that?

Posted: Thu Nov 27, 2008 5:42 pm
by Andyhhp
The whole idea of splitting physical and virtual memory is that you can allocate non-contiguous physical pages and map them to contiguous virtual addresses.

As for managing memory inside a process:

You need to implement functions like 'malloc' or 'new' that will internally use the memory management functions that you have. The job of malloc and new is to keep a record of how much memory you have to access, keep a record of which memory is currently allocated to the process, and to ask the virtual memory manager for more memory if it needs.

There is no easy way to do this and there are many different algorithms for doing so.

Sorry this isn't very helpful

~Andrew

Posted: Tue Dec 02, 2008 4:05 am
by leledumbo
Some questions:
  • Should it be calling virtual or physical allocator?
  • When should I create the heap? Before or after enabling paging?
  • Any small and easy to understand existing code?

Posted: Tue Dec 02, 2008 1:09 pm
by Andyhhp
Good questions:

malloc should use the virtual memory manager if it needs more space. the virtual memory manager should in tern use the physical memory manager when needing another page or for swapping pages to and from main memory.

It makes much more sense to create the heap after after enabling paging because that allows you to maintain a contiguous heap in virtual memory, even if the physical pages of memory used are not contiguous.

As for code, I am sorry but I haven't got this far with my kernel (too much work :( ).

Hope this helps,

~Andrew