memory allocating

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

memory allocating

Post 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
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: memory allocating

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: memory allocating

Post by Combuster »

Not true - Linux uses a zoned buddy allocator for physical memory management, and a more traditional slab allocator for heap management.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: memory allocating

Post 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
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: memory allocating

Post 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.
Every good solution is obvious once you've found it.
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: memory allocating

Post 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
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: memory allocating

Post 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:
Post Reply