Page 1 of 1

Memory Management: Will this work?

Posted: Sun Jun 03, 2007 11:11 pm
by pcmattman
I'm about to re-implement my memory manager (ATM it's just using a running integer that has the top of the heap in it).

My kernel is not going to use paging. So it should be simple to implement a memory manager, I think.

I'm thinking of implementing the same style of memory manager as shown in http://www.koders.com/c/fid2F3F21877FD9 ... C4A26.aspx

Is this a good system, or is there a better, more efficient way of doing this?

Posted: Mon Jun 04, 2007 1:23 am
by pcmattman
OK, I implemented it, keeping the copyright info as well. I'm happy to see it works perfectly, and (unlike my old memory manager) has no bugs!

Previously, the allocated memory ran all over the place, into other variable's memory, and it was a total mess.

Now I can actually do stuff with my kernel :D

Posted: Mon Jun 04, 2007 4:55 am
by XCHG
I'm glad you have your memory manager working but I thought maybe this will help you if you want to code your own memory manager. I am coding in NASM and thus I have to keep track of every memory location that I use. For now I am using MEGABYTE(0) to MEGABYTE(16) for my kernel and MEGABYTE(16) to MEGABYTE(24) for my physical memory manager's free space and I have defined constant values like this:

Code: Select all

; ——————————————————————————————————————————————————
  MEM_MAP_KERNEL_DOMAINSTART          EQU       MEGABYTE(0)
  MEM_MAP_KERNEL_DOMAINLENGTH         EQU       MEGABYTE(8)
  MEM_MAP_KERNEL_DOMAINEND            EQU       MEM_MAP_KERNEL_DOMAINSTART + MEM_MAP_KERNEL_DOMAINLENGTH - 1
  MEM_MAP_KERNEL_ENTRY                EQU       MEGABYTE(1)
  ; ——————————————————————————————————————————————————
  MEM_MAP_PDES_DOMAINSTART            EQU       MEM_MAP_KERNEL_DOMAINEND + 1
  MEM_MAP_PDES_DOMAINLENGTH           EQU       KILOBYTE(4)
  MEM_MAP_PDES_DOMAINEND              EQU       MEM_MAP_PDES_DOMAINSTART + MEM_MAP_PDES_DOMAINLENGTH - 1
  MEM_MAP_PDES_ENTRY                  EQU       MEM_MAP_PDES_DOMAINSTART
  ; ——————————————————————————————————————————————————
  MEM_MAP_PTES_DOMAINSTART            EQU       MEM_MAP_PDES_DOMAINEND + 1
  MEM_MAP_PTES_DOMAINLENGTH           EQU       MEGABYTE(4)
  MEM_MAP_PTES_DOMAINEND              EQU       MEM_MAP_PTES_DOMAINSTART + MEM_MAP_PTES_DOMAINLENGTH - 1
  MEM_MAP_PTES_ENTRY                  EQU       MEM_MAP_PTES_DOMAINSTART
  ; ——————————————————————————————————————————————————
And I always refer to these instead of using variable memory locations and so if I need to change the location of these values I will just change the way they are declared.