Allocate a block of the given size
| 1128 | |
| 1129 | //! Allocate a block of the given size |
| 1130 | static void* |
| 1131 | _memory_allocate(size_t size) { |
| 1132 | if (size <= MEDIUM_SIZE_LIMIT) |
| 1133 | return _memory_allocate_from_heap(_memory_thread_heap, size); |
| 1134 | else if (size <= LARGE_SIZE_LIMIT) |
| 1135 | return _memory_allocate_large_from_heap(_memory_thread_heap, size); |
| 1136 | |
| 1137 | //Oversized, allocate pages directly |
| 1138 | size += SPAN_HEADER_SIZE; |
| 1139 | size_t num_pages = size / PAGE_SIZE; |
| 1140 | if (size % PAGE_SIZE) |
| 1141 | ++num_pages; |
| 1142 | span_t* span = _memory_map(num_pages); |
| 1143 | atomic_store32(&span->heap_id, 0); |
| 1144 | //Store page count in next_span |
| 1145 | span->next_span = (span_t*)((uintptr_t)num_pages); |
| 1146 | |
| 1147 | return pointer_offset(span, SPAN_HEADER_SIZE); |
| 1148 | } |
| 1149 | |
| 1150 | //! Deallocate the given block |
| 1151 | static void |
no test coverage detected