Of course it is better and safer to use malloc and free, I just made it for a (sort of) virtual machine I was trying to make.
It wasn't actually a new memory manager.
I still used malloc to get the large chunk from the system.
After that I made a huge char array from it, and gave the sizeof(required) amount from it to the required object by casting it to a void*.
I read that this process(except some small details) was an old tradition in unix programming before the advent of the standards.
That was actually my goal; to provide an abstraction for allocating memory to objects from the memory owned by the program(there, the virtual machine).
Is that possible with malloc?
First I tried it with realloc but couldn't get the address of the remaining pool(if not returned to the system) after it was done.
I thought that is what 'guestcheap' had in mind; since the other alternative wasn't very viable.
Can't answer for linux but on Windows it's easy enough the OS actually provides this as API calls...
Heap Functions (Windows)
Basically you create a private heap... but it also gives you far better functionality than malloc() and free()... for example you can discover the size of any memory block with HeapSize() and you can confirm HeapFree() with HeapValidate()...
I've often noticed that people seem naturally prone to go in the wrong direction ... they avoide the OS and it's first level APIs like they're going to die if they use them, when in fact getting closer to the core OS very often reveals increased power and capability.
The Linux kernel api is still a little complicated for me because my unfortunate ignorance of most of the C standard library. I'm working to rectify that.
Also, I'd be in a bad situation if someday, I need to demonstrate my program to someone coming from another platform.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}