Xcp wrote:
To pop an address from the stack I should decrement the stack pointer (in my case *pStack), but I'm not physically popping off it and overwriting the memory location, so it should be possible to re-push it simply by incrementing pStack. Am I right?
wrong
physical addresses are rarely ever freed in the same (reverse) order they are allocated in, so yes, you must place the value back onto the stack (overwriting whatever was at that address before -- because what was there before was probably a different address)
Quote:
I intend, when I pop an address I theoretically have to cancel the content and then decrement the stack pointer, but so when I push an address I don't know whether an address is usable or not. Thus I thought that I could not cancel the popped off address and, when I want to push an address, I don't push a specific one but I push the last popped address. But the problem came up anyway when I want to allocate a specific address, how should I check if it is usable or not?
if you are freeing non-existant pages, then you have a very serious problem in your code, and this check will not help you
basically, you will never free a page unless you were using that page, and if you were using that page, then you know it does exist, therefore, there is no need to check the memory map to see if that page really exists, because if it didn't exist you wouldn't be freeing it (and if you were freeing pages incorrectly, checking the memory map wouldn't help, because you could be freeing the wrong address but still a valid address)