I have a little bit of confusion.

Take an example of a program compiled in windows in C which makes a call to malloc. now if one were to look inside the code of malloc , one would find that it eventually calls HeapAlloc to alloacte the memory, which is quite obvious as it cant allocate memory itself without eventually telling the os to do so.

now here comes the confusing part.
Even if the c library is statically linked to the exe, it would still have to eventually make a call to HeapAlloc to allocate memory, as it cannot copy the code inside the api calls to the exe (other wise all our exes would be over a gig in size ;) ).

Now when we are making our own operating system and in our code me make a call to memalloc , it would again search for heapalloc function to allocate the memory. Now how would this take place, as in our own os there is now such function as HeapAlloc. so what exactly would happen at that time and how would memory eventually be allocated?
Posted on 2003-07-16 21:07:49 by clippy

Now when we are making our own operating system and in our code me make a call to memalloc , it would again search for heapalloc function to allocate the memory. Now how would this take place, as in our own os there is now such function as HeapAlloc. so what exactly would happen at that time and how would memory eventually be allocated?
There is no function for HeapAlloc, or WindowsOS support -- the program would crash or something unplanned. ;) Unless you have added a memory manager to your OS there is no management of memory beyond your use of it.
Posted on 2003-07-16 22:09:18 by bitRAKE
So while designing your operating system. obviously the code doesnt even even know anything about creating variables on the stack also.
even to write the memory manager you need some variables in your program to keep track of everything.
So how are objects created when writing say even the memory manager??? :confused:
and also then isnt it a compulsion to create the memory manager before any other part of the os?
Posted on 2003-07-17 00:52:52 by clippy
In your OWN OS you MUST amke almost ALL things by yourself...

You have to boot the machine in some way and setup yourself a basic memory model first.
In my case this "basic" meany plain acces to all RAM from 0 to 4G for data code and stack selectors.

Stack exists in CPU/RAM so you can safely use it and stack/local variables IF you have a valid stack selector.
So STDCALL, C, calling conventins can be used also.

You say "the code" but who is the code? i think you mean "the C compiler" ?

I care less a bout C compiler but i am sure they can still use the stack if a suitable stack selector /setup is provided before you start the C code, but you have to deeply understand the internals ways of the C compiler that you are using for that...

Instead of C i use ASM -- and i have no problems about what "my code" knows -- it knows nothing -- I KNOW ALL instead :). I like to be the one that has all the Knowledge and keep my compilers just doing the hard and not so fancy work for me :)

Memory management - allocation is just a fancy word for some bookkeeping that the OS must do regarding where memory space is available and who uses what from that space...

Clearly the first steep must relay on something absolute -- like the fact that the bootloader is loaded at 0000:7C00 -- and OS must keep some absolute stuff also

Relative memory management will only be needed for real applications and/or latter parts of the kernel.

Yes it will be needed pretty soon in a real OS but there are MANY things that are needed BEFORE that for sure...


I feel there is much confusion there in you about thingks so keep refineing your questions until you will understand it ...
Posted on 2003-07-17 03:25:41 by BogdanOntanu