Page 1 of 1

Heap Manager

Posted: Mon Dec 11, 2006 10:45 am
by Tolga
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.

No answer

Posted: Mon Dec 11, 2006 1:23 pm
by Tolga
hmm. No answer. Probably, i will stop os project. :(

Posted: Mon Dec 11, 2006 3:04 pm
by AJ
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... :roll:

Adam

Re: No answer

Posted: Mon Dec 11, 2006 3:42 pm
by Candy
Tolga wrote:hmm. No answer. Probably, i will stop os project. :(
You go from publishing ideas to giving up within 3 hours? Are you sure you have the motivation to develop an OS?

Re: Heap Manager

Posted: Mon Dec 11, 2006 3:50 pm
by Combuster
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

Posted: Mon Dec 11, 2006 4:06 pm
by Tolga
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?

Posted: Mon Dec 11, 2006 4:54 pm
by Walling
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?
Then you would do something like this:

Code: Select all

class TSystem{
public:
    void print(){}
};

int main() {
    TSystem* System = new TSystem();
    // ... use System ...
    delete System;
}
This requires a memory manager. A simpler solution is to create a global object, like this:

Code: Select all

TSystem System;

int main() {
    // ... use System ...
}
This is easier to implement. Read about it in the C PlusPlus article.

Posted: Mon Dec 11, 2006 4:58 pm
by Walling
Forgot to say that a global object can be accessed from other functions as well, just include this:

Code: Select all

extern TSystem System;

void someOtherFunction() {
    // ... use System ...
}
When linking the files to a binary all references to the System variable will be resolved.

Posted: Tue Dec 12, 2006 12:08 am
by Tolga
Ok. But i will write string class. And strings allocates more space in stack. I dont want this. So i must write heap manager.

Posted: Tue Dec 12, 2006 2:30 am
by AJ
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

Posted: Tue Dec 12, 2006 12:02 pm
by Tolga
All of details for heap manager at attachment. Maybe some codes are wrong. But important thing is idea.

Posted: Wed Dec 13, 2006 11:18 am
by Tolga
What are you doing for heap management? I will write also memory manager after heap management.