Swiftでメモリ圧迫テストするやつ
code:swift
private var pointerArray = UnsafeMutablePointer<UnsafeMutableRawPointer?>.allocate(capacity: 1024 * 1024)
func allocateDirtyBlock(_ size: Int) -> UnsafeMutableRawPointer? {
let block = UnsafeMutablePointer<UInt8>.allocate(capacity: size)
for offset in 0..<size {
blockoffset = UInt8(offset & 0xff) }
return UnsafeMutableRawPointer(block)
}
let times = 6400 // <<<<<<<<<<< 使用デバイスによって違うのでいい塩梅見つけて!
for index in 0..<times {
pointerArrayindex = allocateDirtyBlock(256 * 1024) }
これをChatGPTに変換してもらった