Idea for virtual memory allocator: yea or nay? [verdict:nay]

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.
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Idea for virtual memory allocator: yea or nay? [verdict:

Post by nexos »

An O(n) algorithm would be like this

Code: Select all

for(int i = 0; i < num; ++i)
{
    do something;
}
An O(1) algorithm would be like this

Code: Select all

do something;
The difference, an O(1) algorithm always executes in the same amount of time no matter what. It is also much faster in must circumstances, as a block of code will execute once only. An O(n) algorithm is a bitmap, for example, you loop through every bit in the map to find a free one. A free list is a O(1) algorithm, it has its info right there. No looping needed.
Graphed, you can see the difference. Here are some links to what these algorithm types look like graphed
Image
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
User avatar
eekee
Member
Member
Posts: 891
Joined: Mon May 22, 2017 5:56 am
Location: Kerbin
Discord: eekee
Contact:

Re: Idea for virtual memory allocator: yea or nay? [verdict:

Post by eekee »

Not parameters, but rather finding a place to put the requested allocation. As a simple example, if a free list gets very long, it could take a long search to find a suitably-sized entry, and there's poor cache locality all the way.
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Idea for virtual memory allocator: yea or nay? [verdict:

Post by neon »

Hi,

This is what I like about free stacks as they can be written as O(1).
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Idea for virtual memory allocator: yea or nay? [verdict:

Post by nexos »

neon wrote:Hi,

This is what I like about free stacks as they can be written as O(1).
Yep. I am trying to make most of my system use O(1) algorithms, hoping that might be useful if I decide to support hard real time, and is altogether better for performance.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Post Reply