| // Copyright 2009 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // Fixed-size object allocator. Returned memory is not zeroed. |
| // See malloc.h for overview. |
| // Initialize f to allocate objects of the given size, |
| // using the allocator to obtain chunks of memory. |
| func fixAlloc_Init(f *fixalloc, size uintptr, first func(unsafe.Pointer, unsafe.Pointer), arg unsafe.Pointer, stat *uint64) { |
| f.first = *(*unsafe.Pointer)(unsafe.Pointer(&first)) |
| func fixAlloc_Alloc(f *fixalloc) unsafe.Pointer { |
| print("runtime: use of FixAlloc_Alloc before FixAlloc_Init\n") |
| throw("runtime: internal error") |
| v := unsafe.Pointer(f.list) |
| if uintptr(f.nchunk) < f.size { |
| f.chunk = (*uint8)(persistentalloc(_FixAllocChunk, 0, f.stat)) |
| f.nchunk = _FixAllocChunk |
| v := (unsafe.Pointer)(f.chunk) |
| fn := *(*func(unsafe.Pointer, unsafe.Pointer))(unsafe.Pointer(&f.first)) |
| f.chunk = (*byte)(add(unsafe.Pointer(f.chunk), f.size)) |
| f.nchunk -= uint32(f.size) |
| func fixAlloc_Free(f *fixalloc, p unsafe.Pointer) { |