Memory Manager Question.

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
User avatar
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

Memory Manager Question.

Post 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
grimpy
Posts: 11
Joined: Thu May 03, 2007 11:27 am

Re: Memory Manager Question.

Post 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.
User avatar
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

Post 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
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

There are a lot of good tutorials at Bona Fide

Look for the ones labeled Memory Management for a start.
Post Reply