Heap Manager

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 Manager

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

No answer

Post by Tolga »

hmm. No answer. Probably, i will stop os project. :(
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 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
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: No answer

Post 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?
User avatar
Combuster
Member
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

Post 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
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Tolga
Member
Member
Posts: 28
Joined: Thu Nov 16, 2006 12:08 am

Post 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?
User avatar
Walling
Member
Member
Posts: 158
Joined: Mon Dec 04, 2006 6:06 am
Location: Berlin, Germany

Post 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.
User avatar
Walling
Member
Member
Posts: 158
Joined: Mon Dec 04, 2006 6:06 am
Location: Berlin, Germany

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

Post 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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

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

Post by Tolga »

All of details for heap manager at attachment. Maybe some codes are wrong. But important thing is idea.
Attachments
Heap Manager
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.
User avatar
Tolga
Member
Member
Posts: 28
Joined: Thu Nov 16, 2006 12:08 am

Post by Tolga »

What are you doing for heap management? I will write also memory manager after heap management.
Post Reply