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.
Heap In Memory
Heap In Memory
- Attachments
-
- Heap
- Segments Heap Stack.png (18.62 KiB) Viewed 876 times
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..
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.
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
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
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.
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.