Page 1 of 1

memory allocating

Posted: Tue Jun 02, 2009 1:20 pm
by i586coder
Hi guys,

This day i have couple topics related to allocating -memory no matter on hard drive or RAM- to sharing with you

1)what is the best primary memory(RAM) allocation strategy e.g (first,best,worst),
and you choice depend on MFT(multiprogramming with fixed number of tasks) or MVT(multiprogramming with variable number of tasks),...for i'm using MFT

ok, my os now is look like DOS but with some multi-tasking
2)Single user contiguous memory like DOS, but UNIX systems use paging & virtual memory , why should i use virtual memory,and even windows use .swp file for this purpose.

CheerS,
a.T.d

Re: memory allocating

Posted: Tue Jun 02, 2009 4:25 pm
by NickJohnson
There are many ways of allocating memory. I generally use an optimized bitmap for low level stuff (pages/frames) because it is simple, compact, and predictable. The heap is much more complex, and there are many algorithms out there - for example, Linux uses a "buddy allocator" which wastes a lot of address space but is very fast. The user heap and the kernel heap are also separate, so you can use different algorithms for different situations. I'm not sure why you want to use a fixed number of tasks though - it's not that hard to make a dynamically expanding set of tasks, and hugely more flexible. You should either go with the single tasking approach or the full multitasking approach.

Virtual memory is very very useful, at least if you're doing multitasking. It allows you to use memory efficiently, protect tasks from each other, and do things like swapping. Windows definitely uses virtual memory too (above 95, that is), which is why it can support a swapfile/pagefile/whatever you want to call it.

Re: memory allocating

Posted: Tue Jun 02, 2009 5:19 pm
by Combuster
Not true - Linux uses a zoned buddy allocator for physical memory management, and a more traditional slab allocator for heap management.

Re: memory allocating

Posted: Fri Jun 05, 2009 12:42 am
by i586coder
OK, now i'm gonna to write my own malloc();
so whats your advice to use (first,worst,best)-strategy to implements malloc :? :!:

CheerS,
a.T.d

Re: memory allocating

Posted: Fri Jun 05, 2009 1:06 am
by Solar
No easy answer on that.

Try the old standby "A memory allocator" by Doug Lea, which I consider a must-have-read before writing your own malloc(), and probably Hoard: A Scalable Memory Allocator for Multithreaded Applications by by Berger, McKinley, Blumofe and Wilson.

You'll know more about your options then.

Re: memory allocating

Posted: Wed Jun 10, 2009 7:54 am
by i586coder
Thanx "Solar",.....

...,theory,theory, and theory that all i got from those documents, hehehe whatever :shock:
by chance i found this URL: http://www.delorie.com/djgpp/malloc/
talking about malloc() and has implementation, everything goes alright but that site
didn't mention any thing about fragmentation in malloc() algorithm,
so what do you think about malloc() in that URL good or !good :roll:

CheerS :mrgreen: ,
a.T.d

Re: memory allocating

Posted: Wed Jun 10, 2009 9:31 am
by yemista
Which malloc are you referring to? There were a lot there. I think malloc0.c is definately the fastest malloc Ive ever seen, but I wouldnt recomment using it :wink: