Heap In Memory

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
Tolga
Member
Member
Posts: 28
Joined: Thu Nov 16, 2006 12:08 am

Heap In Memory

Post by Tolga »

Hi. We spoke this subject. But, still i need help.

I learn that (in old heap messages) C assumes that DS = SS = ES. So i think that, i will create 3 segment for a task:

1. Code
2. Data
3. Stack (Heap in this)

But Stack bigger that code and data segments. Beacuse stack may grow onto codes. (can this be ??) And another reason. Heap needs some space. Heap starts in stack segment at code segment finished segment. (is this sentence wrong? english isnt my native language)

#1 : Is this a good idea? Do other oses use heap like that?
#2 : When i creating a new task, how can i know that how much space need?

Thanks.
Attachments
Heap
Heap
Segments Heap Stack.png (18.62 KiB) Viewed 877 times
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Post by bubach »

wow.. sorry, i don't have any answer for you but just had to comment on that
nice looking image, you must be a good photoshoper/gimper.. :)
Last edited by bubach on Tue Jan 16, 2007 6:17 pm, edited 1 time in total.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Tolga
Member
Member
Posts: 28
Joined: Thu Nov 16, 2006 12:08 am

Post by Tolga »

:wink: Thanks. If i can finish my os, i will start to create GUI. But now, i'm still coding. :(
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

Not sure *exactly* what you are asking, but I would suggest you have two segments, one code and one data. You can then place the stack at the top of the data segment (or wherever you want) and you can use an alternative place in the same segment for the heap.

To stop the heap and stack colliding, simply have an un-mapped page between the two. This will cause a page fault if your stack grows too big.

If you use paging, you also don't have to worry about how much each task needs - each task will see a 4GB segment, and you can just page in memory as and when required.

BTW - I have to agree with bubach about the image! How about images like that when needed in the wiki :)

Cheers,
Adam
ntfs
Posts: 19
Joined: Tue Dec 12, 2006 9:55 am
Location: Czech Republic Prague

Post by ntfs »

Great image, really.
The most common is to have code data and stack the same 0-4GB(satck might be limited, eg 3-4gb). Reason is that in C++ you can for example create object on stack and than reference it and language can not not if it is on stack or heap. So that map of 4gb looks as follows usallly:code,data,heap,unallocated,stack. Don't worry about overwriting data. Just be sure there is limit for stack or(more common) that the unallocated page will trigger some exception or error singal etc when acceses.
Post Reply