by bat78 » Tue Feb 03, 2015 12:57 pm
It is not too late for you to learn.
#define dma malloc, calloc, realloc
Functions for memory-management provided by stdlib.h are rather specific. They invoke operations of expanding the heap. Heap is part of the RAM, so as many other instances, independently of them being a read-only memory or not. One application can not access exactly the same memory that another application uses.. that's why there is the notion "Virtual Memory". Every process runs in its own virtual memory. In order to access such a memory, you can perform IPC or (Inter-Process Communication), communication through the processes's memories with memory-mapped i/o, but it is complex and it requires the unforgivable keg of wisdom.
Your problem must be caused by the "UFB Event" or Event caused by the function's undefined behavior. In this case the UB is not literal it is just that we don't know how the function behaves. In simpler words, dma are smart functions that doesn't always just "allocate" memory for us.
If you are allocating a small amount of bytes, dma will most likely find the best place in the heap, that will be dedicated for the data.
However if you are allocating more bytes, these functions might need to expand the heap, which means they have to proceed more operations, which means the application will slow down.
When a call of free has been parsed, the free is just as smart as dma and it may or may not give back that memory available to the OS, but to another call of dma. It will not shrink back the heap. This is very dangerous task after all, especially if you have a lot of timely memory i/o.
Conclusion you can't rely on free shrinking the heap, therefore the amount of RAM consumed by the whole application may stay still.
As for the speed, data saved on stack (statically allocated) will be much faster accessed, because the program will just decrement the stack pointer.
The future of "Game-Editor" here