Heap Manager
Heap Manager
Hi all. I have started to writing kernel headers. Im using C++(mingw). Now to continue, i must some questions to write heap manager library.
1. Kernel and applications have got 4 gdt entries:
- Code
- Data
- Stack
- Heap
2. Heap manager uses Heap Entry. Example in code;
TSystem *System;
System = TSystem.Create();
TSystem.Create() uses heap manager. Heap manager allocates memory in heap entry. Now, i dont understand something. Malloc allocates space area. But i want to allocate memory with class codes. How can copy class codes to heap memory. Example i will call a function like that:
System->GDT.SetGDTR( 0x500 );
System is a pointer to indicate System class address in heap entry.
Thanks.
1. Kernel and applications have got 4 gdt entries:
- Code
- Data
- Stack
- Heap
2. Heap manager uses Heap Entry. Example in code;
TSystem *System;
System = TSystem.Create();
TSystem.Create() uses heap manager. Heap manager allocates memory in heap entry. Now, i dont understand something. Malloc allocates space area. But i want to allocate memory with class codes. How can copy class codes to heap memory. Example i will call a function like that:
System->GDT.SetGDTR( 0x500 );
System is a pointer to indicate System class address in heap entry.
Thanks.
Hi,
Not sure of a complete answer to your question as I'm not using c++, but firstly, is it the easiest thing to have separate data, heap and stack segments if you are using c++ (rather than a flatter model - i.e. implement the heap in the data segment).
Secondly, is it the right thing to be trying to write a complete OS if you give up completely after 3 hours of not getting a reply? I started off being fairly impatient with my hobby OS and have had several re-writes from scratch as a result...
Adam
Not sure of a complete answer to your question as I'm not using c++, but firstly, is it the easiest thing to have separate data, heap and stack segments if you are using c++ (rather than a flatter model - i.e. implement the heap in the data segment).
Secondly, is it the right thing to be trying to write a complete OS if you give up completely after 3 hours of not getting a reply? I started off being fairly impatient with my hobby OS and have had several re-writes from scratch as a result...
Adam
Re: No answer
You go from publishing ideas to giving up within 3 hours? Are you sure you have the motivation to develop an OS?Tolga wrote:hmm. No answer. Probably, i will stop os project.
- Combuster
- 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: Heap Manager
Not sure if it helps with your problem, but afaik gcc assumes that the data segment is the same as the heap segment (and possibly even the stack segment), not different. If you want to use different segments, you'll end up with either assembly or some other compiler
For now, selector not important. Important thing is copying class codes. Example, normally, if we create a class, when application started, it pushes this class to stack.
class TSystem{
public:
void print(){}
};
int main(){
TSystem System;
}
Like this, i dont want it in stack, i want to copy it to somewhere(selector not important). Is this possible? If possible, how?
class TSystem{
public:
void print(){}
};
int main(){
TSystem System;
}
Like this, i dont want it in stack, i want to copy it to somewhere(selector not important). Is this possible? If possible, how?
Then you would do something like this:Tolga wrote:Like this, i dont want it in stack, i want to copy it to somewhere(selector not important). Is this possible? If possible, how?
Code: Select all
class TSystem{
public:
void print(){}
};
int main() {
TSystem* System = new TSystem();
// ... use System ...
delete System;
}
Code: Select all
TSystem System;
int main() {
// ... use System ...
}
Forgot to say that a global object can be accessed from other functions as well, just include this:
When linking the files to a binary all references to the System variable will be resolved.
Code: Select all
extern TSystem System;
void someOtherFunction() {
// ... use System ...
}
I think I see what you are getting at now...
As Walling suggested, If you do not want variables assigned on the stack, you must declare them globally. In order to properly initialise global objects in C++ you will need to follow the steps outlined in the 'Global Objects' section of http://www.osdev.org/osfaq2/index.php/D ... %20C%2B%2B.
Although certainly a heap manager would be fairly high up my list of priorities...
Cheers,
Adam
As Walling suggested, If you do not want variables assigned on the stack, you must declare them globally. In order to properly initialise global objects in C++ you will need to follow the steps outlined in the 'Global Objects' section of http://www.osdev.org/osfaq2/index.php/D ... %20C%2B%2B.
Although certainly a heap manager would be fairly high up my list of priorities...
Cheers,
Adam
All of details for heap manager at attachment. Maybe some codes are wrong. But important thing is idea.
- Attachments
-
- Heap Manager
- Heap Manager.jpg (86.77 KiB) Viewed 2021 times
Last edited by Tolga on Tue Dec 12, 2006 1:50 pm, edited 1 time in total.