| ... | ... | @@ -957,12 +957,17 @@ pub var global_allocator = mem.Allocator { |
| 957 | 957 | var some_mem: [100 * 1024]u8 = undefined; |
| 958 | 958 | var some_mem_index: usize = 0; |
| 959 | 959 | |
| 960 | error OutOfMemory; |
| 961 | |
| 960 | 962 | fn globalAlloc(self: &mem.Allocator, n: usize, alignment: usize) -> %[]u8 { |
| 961 | 963 | const addr = @ptrToInt(&some_mem[some_mem_index]); |
| 962 | 964 | const rem = @rem(addr, alignment); |
| 963 | 965 | const march_forward_bytes = if (rem == 0) 0 else (alignment - rem); |
| 964 | 966 | const adjusted_index = some_mem_index + march_forward_bytes; |
| 965 | 967 | const end_index = adjusted_index + n; |
| 968 | if (end_index > some_mem.len) { |
| 969 | return error.OutOfMemory; |
| 970 | } |
| 966 | 971 | const result = some_mem[adjusted_index .. end_index]; |
| 967 | 972 | some_mem_index = end_index; |
| 968 | 973 | return result; |