hook的意思是钩子,那一般在编程的场景中可以翻译成“钩子函数”?
不过翻译成这样对我理解原作者意思并没有啥帮助,查了一下,钩子函数和回调函数是两个不同的意思.
遇到问题的位置:
The hook for this custom memory allocation is the asynchronous operation’s completion handler.
The handler identifies the larger context in which the operation is being performed. By passing this completion handler to the initiating function, Asio is able to allocate the necessary memory prior to signalling the operating system to start the asynchronous operation
hook和回调不是一个东西。用例子来说吧。
假设我要使用http发送请求。
如果我要在请求前加上我的cookie,回调函数做不了,因为此时还没有发出请求,更别说回调结果了。
而钩子函数可以,比如有个
beforeRequest
的钩子,你可以在这里设置一些参数,设置完之后才会真正发出请求