Page 1 of 1

Memory Manager Question.

Posted: Fri May 04, 2007 9:27 am
by astrocrep
Ok, so I am about to begin coding my memory manager. It will use 4k pages (paging enabled).

My question though is how does smaller memory get managed.

Example:

Code: Select all

char *myStr = kmalloc(256);
Basically I am saying, I want a char * ptr to a 256 long buffer... however, when the memory manager gets that kmalloc request, it going to dump 4096 bytes on the request. Is that right?

Or should I just always:

Code: Select all

char myStr[256];
So its compiled with 256 bytes already allocated in the file.

Really confused about this.

Thanks,
Rich

Re: Memory Manager Question.

Posted: Fri May 04, 2007 9:49 am
by grimpy
astrocrep wrote:Ok, so I am about to begin coding my memory manager. It will use 4k pages (paging enabled).

My question though is how does smaller memory get managed.

Example:

Code: Select all

char *myStr = kmalloc(256);
Basically I am saying, I want a char * ptr to a 256 long buffer... however, when the memory manager gets that kmalloc request, it going to dump 4096 bytes on the request. Is that right?
No, you build a virtual memory allocator on top of the page allocator.

In the simplest case, you provide an sbrk() like function in your kernel that a malloc-implementation calls to map and unmap physical pages on demand.

For instance, porting dlmalloc (google it) to a new kernel is fairly easy, and is enough to get you started.

astrocrep wrote: Or should I just always:

Code: Select all

char myStr[256];
So its compiled with 256 bytes already allocated in the file.

Really confused about this.
Preallocating everything is impossible - you need to be able to dynamically allocate memory.

Posted: Fri May 04, 2007 12:35 pm
by astrocrep
I am sorry, I am not following you a 100% w/ the Virtual Allocator... I am doing a strict 1:1 mapping for starters...

Is there any good tutorials on this?

Thanks,
Rich

Posted: Fri May 04, 2007 6:35 pm
by frank
There are a lot of good tutorials at Bona Fide

Look for the ones labeled Memory Management for a start.