| 112 | /* GC_scratch_end_ptr is end point of current scratch area. */ |
| 113 | |
| 114 | ptr_t GC_scratch_alloc(size_t bytes) |
| 115 | { |
| 116 | register ptr_t result = scratch_free_ptr; |
| 117 | |
| 118 | bytes += GRANULE_BYTES-1; |
| 119 | bytes &= ~(GRANULE_BYTES-1); |
| 120 | scratch_free_ptr += bytes; |
| 121 | if (scratch_free_ptr <= GC_scratch_end_ptr) { |
| 122 | return(result); |
| 123 | } |
| 124 | { |
| 125 | word bytes_to_get = MINHINCR * HBLKSIZE; |
| 126 | |
| 127 | if (bytes_to_get <= bytes) { |
| 128 | /* Undo the damage, and get memory directly */ |
| 129 | bytes_to_get = bytes; |
| 130 | # ifdef USE_MMAP |
| 131 | bytes_to_get += GC_page_size - 1; |
| 132 | bytes_to_get &= ~(GC_page_size - 1); |
| 133 | # endif |
| 134 | result = (ptr_t)GET_MEM(bytes_to_get); |
| 135 | scratch_free_ptr -= bytes; |
| 136 | GC_scratch_last_end_ptr = result + bytes; |
| 137 | return(result); |
| 138 | } |
| 139 | result = (ptr_t)GET_MEM(bytes_to_get); |
| 140 | if (result == 0) { |
| 141 | if (GC_print_stats) |
| 142 | GC_printf("Out of memory - trying to allocate less\n"); |
| 143 | scratch_free_ptr -= bytes; |
| 144 | bytes_to_get = bytes; |
| 145 | # ifdef USE_MMAP |
| 146 | bytes_to_get += GC_page_size - 1; |
| 147 | bytes_to_get &= ~(GC_page_size - 1); |
| 148 | # endif |
| 149 | return((ptr_t)GET_MEM(bytes_to_get)); |
| 150 | } |
| 151 | scratch_free_ptr = result; |
| 152 | GC_scratch_end_ptr = scratch_free_ptr + bytes_to_get; |
| 153 | GC_scratch_last_end_ptr = GC_scratch_end_ptr; |
| 154 | return(GC_scratch_alloc(bytes)); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | static hdr * hdr_free_list = 0; |
| 159 |
no test coverage detected