Talking about malloc, free, ...
Actually these functions are nothing more than calls to get memory from the heap, it is an area
that is assigned from the kernel itself to the application generally after the bss,
it is not even initialized, that is, when it is used, a failure occurs
of page, the kernel assigns it a physical page and that's when this memory really exists
physically.
I give you an example in "C" they are usually called malloc, free, ... and they are in the stdlib.h library, this
it is a way of maintaining the standard. Already in c ++ the new and delete operators are used.
I give you an example from the beginning:
In c you can define it in the stdio.h library or wherever you decide, the only important thing here is to know
the kernel call that returns the start of the heap, is usually called with sbrk () as standard
and you can implement your own malloc, free or whatever name you decide.
there is a place where you define these functions to be used in c ++
Code: Select all
// For new operator example int * val = new int;
void * operator new (u32 len) {
malloc (len);
}
// For new operator example int * val = new int [10]
void * operator new [] (u32 len) {
return :: operator new (len);
}
// for delete (val) operators
void operator delete (void * ptr) {
free (ptr);
}
// for delete operators (val [5])
void operator delete [] (void * ptr) {
:: operator delete (ptr);
}
I give you an example when you create for example in c ++
int * new = new int [20]
actually c ++ ends up calling malloc
If you need a deeper detail I can help you, I really had to do all the
implementations to implement the libraries my kernel uses.
I hope these words serve you and help you. Regards