void *operator new (size_t incr) throw(){ return p_malloc(incr); } // Array handling: void * operator new[](size_t incr) { return p_malloc(incr); } extern char _susrstack; // Defined by the linker : _ebss static char *heap_end = 0; void* p_malloc(size_t incr) { char *prev_heap_end; int align; // initial setup if (heap_end == 0) { heap_end = &_susrstack; // &_ebss } prev_heap_end = heap_end; // perform address alignment: align = incr%4; switch (align) { case 0: // align on 4 byte address boundary prev_heap_end += (4-(long)heap_end%4)%4; break; case 2: // align on 2 byte address boundary prev_heap_end += (2-(long)heap_end%2)%2; break; default:; // no alignment: } char * stack = (char*) __get_MSP(); if (heap_end + incr > stack) { // ERROR HANDLING return (void*)-1; //abort (); } heap_end = prev_heap_end+incr; return prev_heap_end; }