flat assembler
Message board for the users of flat assembler.

Index > OS Construction > About malloc()?

Author
Thread Post new topic Reply to topic
ivan_tux



Joined: 23 Jun 2012
Posts: 27
Location: Indonesia
ivan_tux 04 Aug 2013, 11:41
I have read a thread about malloc() at osdev.org
It says that the function should create linked-list to keep allocation information. My question is, where i should put it?
Inside every program or just one for all programs?
Post 04 Aug 2013, 11:41
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 04 Aug 2013, 15:18
ivan_tux,

It should, so it can track those mallocations and free()s. Bitmaps can be used too.

Every program do have private addressing space, yet they share the same physical memory.
Post 04 Aug 2013, 15:18
View user's profile Send private message Reply with quote
ivan_tux



Joined: 23 Jun 2012
Posts: 27
Location: Indonesia
ivan_tux 05 Aug 2013, 01:00
baldr wrote:
Every program do have private addressing space, yet they share the same physical memory.

Hmm.. It sounds confused if programs share the pool area. If the pool is full, malloc call morecore or sbrk to alloc new pages.
Then how each program can know new pool area that doesnt mapped to the programs' address space?
Or, maybe morecore map new allocated pages to each programs?
Post 05 Aug 2013, 01:00
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 05 Aug 2013, 02:44
In protected mode, different processes run in their own address space. Read up on virtual memory.
Post 05 Aug 2013, 02:44
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
ivan_tux



Joined: 23 Jun 2012
Posts: 27
Location: Indonesia
ivan_tux 05 Aug 2013, 03:06
comrade wrote:
In protected mode, different processes run in their own address space. Read up on virtual memory.

Yes i know. And we can share pages to another process. Then, how about malloc?
Does malloc manage pages from address space of current process that requests allocation. or from pages that allocated by malloc itself, and this pages shared and managed for all programs that request allocation? Rrrr... It confuse...
Post 05 Aug 2013, 03:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 05 Aug 2013, 03:47
Since you posted this in OS Construction then can we assume you are writing your own OS? If so then there is no rule for malloc that you must follow. Just do whatever makes sense for your OS. Make malloc do whatever you want/need.
Post 05 Aug 2013, 03:47
View user's profile Send private message Visit poster's website Reply with quote
dogman



Joined: 18 Jul 2013
Posts: 114
dogman 05 Aug 2013, 07:03
Why use malloc() at all? Does the world really need another *NIX clone? Death to POSIX!!! Wink
Post 05 Aug 2013, 07:03
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 05 Aug 2013, 07:14
comrade wrote:
In protected mode, different processes run in their own address space.
Only if the OS supports that mode of operation. There is no rule for this either. If it doesn't make sense for one's OS to support process separation then there is no requirement to do it.
Post 05 Aug 2013, 07:14
View user's profile Send private message Visit poster's website Reply with quote
ivan_tux



Joined: 23 Jun 2012
Posts: 27
Location: Indonesia
ivan_tux 09 Aug 2013, 23:28
dogman wrote:
Why use malloc() at all? Does the world really need another *NIX clone? Death to POSIX!!! Wink
You are right.. I think we should create new one that different Very Happy
Post 09 Aug 2013, 23:28
View user's profile Send private message Reply with quote
Bargest



Joined: 09 Feb 2012
Posts: 79
Location: Russia
Bargest 10 Aug 2013, 07:43
ivan_tux wrote:
It says that the function should create linked-list to keep allocation information.

There are many different ways to manage memory. It is just one of them.
ivan_tux wrote:
My question is, where i should put it?
Inside every program or just one for all programs?

If this function manages physical memory, the list should be global. I use big memory pages (2 MB each), allocate physical memory by pages and store memory bitmap. For 512 GB physical memory it consumes 32kb of map.
If it manages virtual memory of process, the list should be local. But creating such function is not essential for OS, any program can create its own functions and use them for managing user's part of virtual memory.

_________________
jmp $ ; Happy end!
Post 10 Aug 2013, 07:43
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 10 Aug 2013, 08:37
An OS usually keeps track about what app owns what memory. If the app gets assassinated, the memory owned by it is automatically getting freed. So no absolute need for a demalloc at app exit. This works even in good old DOS ("MCB chain").

> Why use malloc() at all? Does the world really need
> another *NIX clone? Death to POSIX!!!

Good point. BTW, I deprecate malloc & Loonix too. But for a better OS, you need better hardware too: http://board.flatassembler.net/topic.php?t=14900
Post 10 Aug 2013, 08:37
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.