+ // Check for free space after the block\r
+ heap_head *nexthead = NEXT_HEAD(head);\r
+ assert( nexthead <= _heap_end );\r
+ if( nexthead != _heap_end && nexthead->magic == MAGIC_FREE && head->size + nexthead->size >= reqd_size )\r
+ {\r
+ // Split next block\r
+ if( head->size + nexthead->size > reqd_size )\r
+ {\r
+ size_t newblocksize = nexthead->size - (reqd_size - head->size);\r
+ head->size = reqd_size;\r
+ \r
+ nexthead = NEXT_HEAD(head);\r
+ nexthead->size = newblocksize;\r
+ nexthead->magic = MAGIC_FREE;\r
+ THIS_FOOT(nexthead)->header = nexthead;\r
+ }\r
+ else\r
+ {\r
+ head->size = reqd_size;\r
+ }\r
+ THIS_FOOT(head)->magic = MAGIC;\r
+ THIS_FOOT(head)->header = head;\r
+ head->RealSize = bytes;\r
+ return oldPos;\r
+ }\r