How does the compiler allocate RAM on the WeMOS D1 mini?
Posted: Sun Aug 07, 2016 11:29 pm
I would have expected that global and static variables would be located at the bottom of RAM, the heap would grow upwards from there. The stack would begin at the top of RAM and would grow downwards from there.
This is without knowing anything about the architecture, registers or instruction set of the ESP8266 CPU.
I have written this little routine based on the above assumptions and it gives the amount of memory free as a negative number, so obviously the assumptions are wrong. Can someone correct me please?
long RAMfree(void) {
long free_memory;
uint8_t stackObject, *heapObjPtr, *stackObjPtr = &stackObject;
heapObjPtr = new uint8_t;
free_memory = (uint32_t)stackObjPtr - (uint32_t)heapObjPtr;
Serial.printf("\nIn RAMfree(): stackPtr = \'%lX\', heapPtr = \'%lX\', free memory = \'%ld\'\n", stackObjPtr, heapObjPtr, free_memory);
delete heapObjPtr;
return free_memory;
}
Thanks,
Peter.
This is without knowing anything about the architecture, registers or instruction set of the ESP8266 CPU.
I have written this little routine based on the above assumptions and it gives the amount of memory free as a negative number, so obviously the assumptions are wrong. Can someone correct me please?
long RAMfree(void) {
long free_memory;
uint8_t stackObject, *heapObjPtr, *stackObjPtr = &stackObject;
heapObjPtr = new uint8_t;
free_memory = (uint32_t)stackObjPtr - (uint32_t)heapObjPtr;
Serial.printf("\nIn RAMfree(): stackPtr = \'%lX\', heapPtr = \'%lX\', free memory = \'%ld\'\n", stackObjPtr, heapObjPtr, free_memory);
delete heapObjPtr;
return free_memory;
}
Thanks,
Peter.