简单类型 / 指针

//Memory for several values at once
let count = 3
let buffer = UnsafeMutablePointer<Int>.allocate(
    capacity: count)
buffer.initialize(repeating: 0, count: count)

for i in 0 ..< count {
    buffer[i] = (i + 1) * 10
}
//buffer[1] is 20
print("buffer[1] is \(buffer[1])")

//Raw memory knows nothing about the type: it is
//asked for BYTES and for an alignment
let raw = UnsafeMutableRawPointer.allocate(
    byteCount: 8, alignment: 8)
raw.storeBytes(of42asInt.self)
let stored = raw.load(asInt.self)
//stored is 42
print("stored is \(stored)")

//Nothing here is released by itself
buffer.deinitialize(count: count)
buffer.deallocate()
raw.deallocate()
print("memory is released")