리눅서가 맥을 쓰더라도 터미널이 편할 것이다. locate 명령이 듣지 않아 에러 로그를 보면
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
으로 나온다.
그럴 땐, 다음 명령어 이후 locate를 하면 잘 된다.
sudo /usr/libexec/locate.updatedb
스위프트는 포인터의 언어
withUnsafePointer(to:_:)
import UIKit
var str = "A String"
withUnsafePointer(to: &str) {
let c : Int = 4
print(" str value \(str) has address: \($0)")
str = "Hello"
}
print(str)
print(c)
str은 잘 나오고 c는 당연히 나오지 않는다.
의식의 흐름 따라 만들다... 통째로 떼서 function이나 class 로 분리하면 된다.
mutable 을 이용하여 메모리 할당, 해제, 제어 등이 가능하다는 것도 알아두자.
여러 개념과 많은 오픈소스와 여러 라이브러리로 프로그램을
쌓아올리다보니 결국에 꼬이는 현상이 발생해서 메모리를 직접 제어할 경우가 결국 오고야 만다.
사실 메모리 직접 제어가 가장 깔끔하다. 리셋이나 무한 루프야 메모리 개념 배제해도 결국 생기는
오류. 큰 프로젝트 하다보면 사실, 칩이나 컴파일러도 의심이 갈 수 밖에 없다.
swift standard library 에서 menual memory management 에 다른 API가 많다.
애플 설명서를 블로그에 붙여넣는 짓은 최대한 지양하려고 한다.
이전 글에도 밝혔지만, 스위프트에서 포인터 이야기하니 언어는 그 언어 자체로서 말해야 한다는 앵무새를 또 만나,...
지양하지 못하고 붙여 넣는다.
Article
Calling Functions With Pointer Parameters
Use implicit pointer casting or bridging when calling functions that takes pointers as parameters.
Framework
Swift Standard Library
Overview
When calling a function that takes a pointer as a parameter, you can use implicit casting to pass a compatible pointer type or implicit bridging to pass a pointer to a variable or the contents of an array.
Pass a Constant Pointer as a Parameter
When you call a function that is declared as taking an UnsafePointer<Type> argument, you can pass any of the following:
An UnsafePointer<Type>, UnsafeMutablePointer<Type>, or AutoreleasingUnsafeMutablePointer<Type> value, which is implicitly cast to UnsafePointer<Type> as necessary.
A String value, if Type is Int8 or UInt8. The string is automatically converted to UTF8 in a zero-terminated buffer, and a pointer to that buffer is passed to the function.
An in-out expression that contains a mutable variable, property, or subscript reference of type Type, which is passed as a pointer to the address of the left-hand side identifier.
A [Type] value, which is passed as a pointer to the start of the array.
The pointer you pass to the function is guaranteed to be valid only for the duration of the function call. Do not persist the pointer and access it after the function has returned.
This example shows the different ways that you can call the a function that takes a constant pointer:
func takesAPointer(_ p: UnsafePointer<Float>) {
// ...
}
var x: Float = 0.0
takesAPointer(&x)
takesAPointer([1.0, 2.0, 3.0])
When you call a function that takes an UnsafeRawPointer argument, you can pass the same operands as UnsafePointer<Type>, but with any type as Type.
This example shows the different ways that you can call a function that takes a constant raw pointer:
func takesARawPointer(_ p: UnsafeRawPointer?) {
// ...
}
var x: Float = 0.0, y: Int = 0
takesARawPointer(&x)
takesARawPointer(&y)
takesARawPointer([1.0, 2.0, 3.0] as [Float])
let intArray = [1, 2, 3]
takesARawPointer(intArray)
takesARawPointer("How are you today?")
Pass a Mutable Pointer as a Parameter
When you call a function that is declared as taking an UnsafeMutablePointer<Type> argument, you can pass any of the following:
An UnsafeMutablePointer<Type> value.
An in-out expression of type Type that contains a mutable variable, property, or subscript reference, which is passed as a pointer to the address of the mutable value.
An in-out expression of type [Type] that contains a mutable variable, property, or subscript reference, which is passed as a pointer to the start of the array, and is lifetime-extended for the duration of the call.
This example shows the different ways that you can call a function that takes a mutable pointer:
func takesAMutablePointer(_ p: UnsafeMutablePointer<Float>) {
// ...
}
var x: Float = 0.0
var a: [Float] = [1.0, 2.0, 3.0]
takesAMutablePointer(&x)
takesAMutablePointer(&a)
When you call a function that is declared as taking an UnsafeMutableRawPointer argument, you can pass the same operands as UnsafeMutablePointer<Type>, but for any type as Type.
This example shows the different ways that you can call a function that takes a mutable raw pointer:
func takesAMutableRawPointer(_ p: UnsafeMutableRawPointer?) {
// ...
}
var x: Float = 0.0, y: Int = 0
var a: [Float] = [1.0, 2.0, 3.0], b: [Int] = [1, 2, 3]
takesAMutableRawPointer(&x)
takesAMutableRawPointer(&y)
takesAMutableRawPointer(&a)
takesAMutableRawPointer(&b)
Pass an Autoreleasing Pointer as a Parameter
When you call a function that is declared as taking an AutoreleasingUnsafeMutablePointer<Type>, you can pass any of the following:
An AutoreleasingUnsafeMutablePointer<Type> value.
An in-out expression that contains a mutable variable, property, or subscript reference of type Type. The value of the operand is copied bitwise into a temporary nonowning buffer. The address of that buffer is passed to the callee, and on return, the value in the buffer is loaded, retained, and reassigned into the operand.
Unlike with other pointer types, you can't use an array as an implicitly bridged parameter.
Pass a Function Pointer as a Parameter
When calling a function that takes a C function pointer argument, you can pass a top-level Swift function, a closure literal, a closure declared with the @convention(c) attribute, or nil. You can also pass a closure property of a generic type or a generic method as long as no generic type parameters are referenced in the closure’s argument list or body.
For example, consider Core Foundation’s CFArrayCreateMutable(_:_:_:) function. The CFArrayCreateMutable(_:_:_:) function takes a CFArrayCallBacks structure, which is initialized with function pointer callbacks:
func customCopyDescription(_ p: UnsafeRawPointer?) -> Unmanaged<CFString>? {
// return an Unmanaged<CFString>? value
}
var callbacks = CFArrayCallBacks(
version: 0,
retain: nil,
release: nil,
copyDescription: customCopyDescription,
equal: { (p1, p2) -> DarwinBoolean in
// return Bool value
}
)
var mutableArray = CFArrayCreateMutable(nil, 0, &callbacks)
In this example, the CFArrayCallBacks initializer uses nil values as arguments for the retain and release parameters, the customCopyDescription(_:) function as the argument for the customCopyDescription parameter, and a closure literal as the argument for the equal parameter.
Note
Only Swift function types with C function reference calling convention may be used for function pointer arguments. Like a C function pointer, a Swift function type with the @convention(c) attribute does not capture the context of its surrounding scope.
알아야 하는 사이트와 솔루션
그래서 집에 감기약 많이 사뒀지만
많이 아파야 약을 먹게 된다.
결국엔 많이 아플 수 밖에 없다.
허리도 마찬가지.
난 손목이나 허리 누가 미리 말을 해줬다면 신경을 썼을텐데
말 안해주었었다.
신기한건 내가 아쉬워서 말을 해주면
안 듣는다.
결국 아파봐야 그 때 후회하며 알게 되는 것 같다.
그래서 이제는
뭔가를 가르쳐 줄 때
미리 포기하는 습관이 생겼다.
조금 말해보고 아니다 싶으면 그냥 경험하게 하는게 좋은 것 같다.
안타깝지만 그것도 자기 능력이라 판단된다.
사람은 변하지 않더라.
20년 경험이다. 중학교 때부터 치면, 더 넘었네.
그래서 이젠 내려놓는다.
Data Recovery
Data Sharing
Explorer Alternatives
Virtual Machine
EXE Security
Beyond Compare, Themida, Browser & Editor , Redhat Cygwin, Kaspersky, Bittorrent series
'C++' 카테고리의 다른 글
make mrproper (0) | 2019.02.04 |
---|---|
스타벅스 텀블러 한정판 (0) | 2019.02.04 |
스위프트 소스 중에 가장 중요한 소스 from swift.org (0) | 2019.02.02 |
gcc -static -> Visual studio (0) | 2019.02.02 |
자료형에 대해서 (0) | 2019.02.02 |
최근댓글