File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -90,8 +90,10 @@ void *psyqo_heap_start();
90
90
*
91
91
* @details This function will return the pointer to the end of the
92
92
* heap. The heap works lazily, and this function may return a NULL
93
- * pointer. Once it returns a non-NULL pointer, it will always return
94
- * the same pointer to the maximum address of the heap.
93
+ * pointer. Once it returns a non-NULL pointer, it will approximately
94
+ * correspond to the current end of the heap. The heap may actually
95
+ * be larger than this pointer on occasion. The heap will always
96
+ * grow, and never shrink.
95
97
*
96
98
* @return void* The end of the heap.
97
99
*/
Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ _Static_assert(sizeof(allocated_block) == (2 * sizeof(void *)), "allocated_block
97
97
static empty_block * head = NULL ;
98
98
static allocated_block * bottom = NULL ;
99
99
static allocated_block * top = NULL ;
100
+ static void * maximum_heap_end = NULL ;
100
101
// The marker is here to make sure that the list is always terminated,
101
102
// so when we completely fill the heap, we don't end up with a NULL pointer
102
103
// back to the head. It will never fit any allocation, and will always
@@ -328,6 +329,10 @@ void *psyqo_malloc(size_t size_) {
328
329
}
329
330
330
331
// Store the size of the allocation before the pointer.
332
+ void * end = (void * )((char * )ptr + size );
333
+ if (end > maximum_heap_end ) {
334
+ maximum_heap_end = end ;
335
+ }
331
336
ptr -> size = size ;
332
337
ptr ++ ;
333
338
@@ -656,4 +661,4 @@ void _ZdlPvj(void *ptr, unsigned int size) { psyqo_free(ptr); }
656
661
void _ZdaPvj (void * ptr , unsigned int size ) { psyqo_free (ptr ); }
657
662
658
663
void * psyqo_heap_start () { return bottom ; }
659
- void * psyqo_heap_end () { return top ; }
664
+ void * psyqo_heap_end () { return maximum_heap_end ; }
You can’t perform that action at this time.
0 commit comments