chrome-base 如何实现一个BindOnce
考虑一个问题:
worker_thread.task_runner()->PostDelayedTask(FROM_HERE, base::BindOnce(&Ref::Foo, ref, 1), base::Milliseconds(1000));
BindOnce 是如何实现的呢?
翻看源码:base\functional\bind.h
写的 非常简洁
// Bind as OnceCallback.
template <typename Functor, typename... Args>
inline OnceCallback<internal::MakeUnboundRunType<Functor, Args...>> BindOnce(Functor&& functor,Args&&... args) {static_assert(!internal::IsOnceCallback<std::decay_t<Functor>>() ||(std::is_rvalue_reference<Functor&&>() &&!std::is_const<std::remove_reference_t<Functor>>()),"BindOnce requires non-const rvalue for OnceCallback binding."" I.e.: base::BindOnce(std::move(callback)).");static_assert(std::conjunction<internal::AssertBindArgIsNotBasePassed<std::decay_t<Args>>...>::value,"Use std::move() instead of base::Passed() with base::BindOnce()");return internal::BindImpl<OnceCallback>(std::forward<Functor>(functor),std::forward<Args>(args)...);
}
重要的也就是最后一句:构造一个BindImpl,同时完美转发
internal::BindImpl<OnceCallback>(std::forward<Functor>(functor),std::forward<Args>(args)...)
base\functional\bind_internal.h
template <template <typename> class CallbackT,typename Functor,typename... Args>
decltype(auto) BindImpl(Functor&& functor, Args&&... args) {// This block checks if each |args| matches to the corresponding params of the// target function. This check does not affect the behavior of Bind, but its// error message should be more readable.static constexpr bool kIsOnce = IsOnceCallback<CallbackT<void()>>::value;using Helper = BindTypeHelper<Functor, Args...>;using FunctorTraits = typename Helper::FunctorTraits;using BoundArgsList = typename Helper::BoundArgsList;using UnwrappedArgsList =MakeUnwrappedTypeList<kIsOnce, FunctorTraits::is_method, Args&&...>;using BoundParamsList = typename Helper::BoundParamsList;static_assert(MakeFunctorTraits<Functor>::is_stateless,"Capturing lambdas and stateful lambdas are intentionally not supported. ""Please use base::Bind{Once,Repeating} directly to bind arguments.");static_assert(AssertBindArgsValidity<std::make_index_sequence<Helper::num_bounds>,BoundArgsList, UnwrappedArgsList,BoundParamsList>::ok,"The bound args need to be convertible to the target params.");using BindState = MakeBindStateType<Functor, Args...>;using UnboundRunType = MakeUnboundRunType<Functor, Args...>;using Invoker = Invoker<BindState, UnboundRunType>;using CallbackType = CallbackT<UnboundRunType>;// Store the invoke func into PolymorphicInvoke before casting it to// InvokeFuncStorage, so that we can ensure its type matches to// PolymorphicInvoke, to which CallbackType will cast back.using PolymorphicInvoke = typename CallbackType::PolymorphicInvoke;PolymorphicInvoke invoke_func;if constexpr (kIsOnce) {invoke_func = Invoker::RunOnce;} else {invoke_func = Invoker::Run;}using InvokeFuncStorage = BindStateBase::InvokeFuncStorage;return CallbackType(BindState::Create(reinterpret_cast<InvokeFuncStorage>(invoke_func),std::forward<Functor>(functor), std::forward<Args>(args)...));
}
BindState的实现
// This stores all the state passed into Bind().
template <typename Functor, typename... BoundArgs>
struct BindState final : BindStateBase {using IsCancellable = std::bool_constant<CallbackCancellationTraits<Functor,std::tuple<BoundArgs...>>::is_cancellable>;template <typename ForwardFunctor, typename... ForwardBoundArgs>static BindState* Create(BindStateBase::InvokeFuncStorage invoke_func,ForwardFunctor&& functor,ForwardBoundArgs&&... bound_args) {// Ban ref counted receivers that were not yet fully constructed to avoid// a common pattern of racy situation.BanUnconstructedRefCountedReceiver<ForwardFunctor>(bound_args...);// IsCancellable is std::false_type if// CallbackCancellationTraits<>::IsCancelled returns always false.// Otherwise, it's std::true_type.return new BindState(IsCancellable{}, invoke_func,std::forward<ForwardFunctor>(functor),std::forward<ForwardBoundArgs>(bound_args)...);}Functor functor_;std::tuple<BoundArgs...> bound_args_;private:static constexpr bool is_nested_callback =MakeFunctorTraits<Functor>::is_callback;template <typename ForwardFunctor, typename... ForwardBoundArgs>explicit BindState(std::true_type,BindStateBase::InvokeFuncStorage invoke_func,ForwardFunctor&& functor,ForwardBoundArgs&&... bound_args): BindStateBase(invoke_func,&Destroy,&QueryCancellationTraits<BindState>),functor_(std::forward<ForwardFunctor>(functor)),bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) {// We check the validity of nested callbacks (e.g., Bind(callback, ...)) in// release builds to avoid null pointers from ending up in posted tasks,// causing hard-to-diagnose crashes. Ideally we'd do this for all functors// here, but that would have a large binary size impact.if (is_nested_callback) {CHECK(!IsNull(functor_));} else {DCHECK(!IsNull(functor_));}}template <typename ForwardFunctor, typename... ForwardBoundArgs>explicit BindState(std::false_type,BindStateBase::InvokeFuncStorage invoke_func,ForwardFunctor&& functor,ForwardBoundArgs&&... bound_args): BindStateBase(invoke_func, &Destroy),functor_(std::forward<ForwardFunctor>(functor)),bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) {// See above for CHECK/DCHECK rationale.if (is_nested_callback) {CHECK(!IsNull(functor_));} else {DCHECK(!IsNull(functor_));}}~BindState() = default;static void Destroy(const BindStateBase* self) {delete static_cast<const BindState*>(self);}
};
其中有两个成员变量:
Functor functor_;std::tuple<BoundArgs...> bound_args_;
其中用到了std::tuple ??
为什么chromium不使用std::bind
相对于std::bind, base::Bind能够帮助我们减少生命周期缺陷:
在使用 base::BindOnce() 方法产生一个 base::OnceClosure 的时候,一般会传递一个 base::WeakPrt,而不是一个裸指针。base::WeakPrt能确保所指向的对象销毁时,绑定在对象上的回调能被取消。否则一般会产生一个段错误。
如果声明裸指针则必须使用Unretained符号。
chromium bind出现的更早,且通过BindOnce与BindRepeating 对生命周期做了更加细致的区分,C++ 14之后好像也有了类似的bind?
c++中的元组
元组基本使用
https://en.cppreference.com/w/cpp/utility/tuple/get c11中引入了 std::tuple,并在后续的c14中扩充了使用方式
#include <iostream>
#include <string>
#include <tuple>int main()
{auto t = std::make_tuple(1, "Foo", 3.14);// index-based accessstd::cout << "(" << std::get<0>(t) << ", " << std::get<1>(t)<< ", " << std::get<2>(t) << ")\n";// type-based access (C++14 or later)std::cout << "(" << std::get<int>(t) << ", " << std::get<const char*>(t)<< ", " << std::get<double>(t) << ")\n";// Note: std::tie and structured binding may also be used to decompose a tuple
}
元组用作函数参数
#include <iostream>
#include <string>
#include <tuple>void foo(int a1, const char* a2, double a3) {// Do somethingstd::cout << a1 << std::endl;std::cout << a2 << std::endl;std::cout << a3 << std::endl;
}int main() {auto t = std::make_tuple(1, "Foo", 3.14);foo(std::get<0>(t), std::get<1>(t), std::get<2>(t));return 0;
}
观察后会发现,配合c++11的可变参数模板,可以写出这样一个函数,整体如下:
https://zhuanlan.zhihu.com/p/465077081
#include <iostream>
#include <string>
#include <tuple>void foo(int a1, const char* a2, double a3) {// Do somethingstd::cout << a1 << std::endl;std::cout << a2 << std::endl;std::cout << a3 << std::endl;
}template <typename F, typename T, std::size_t... I>
void bar(F f, const T& t) {f(std::get<I>(t)...);
}// 或者这样定义也可以
template <std::size_t... I, typename F, typename T>
void bar2(F f, const T& t) {f(std::get<I>(t)...);
}int main() {auto t = std::make_tuple(1, "Foo", 3.14);//foo(std::get<0>(t), std::get<1>(t), std::get<2>(t));bar<decltype(foo), decltype(t), 0, 1, 2>(foo, t);// 少了函数类型和调用类型的模板,这里编译器帮我们做了类型推导bar2<0, 1, 2>(foo, t);return 0;
}
使用std::index_sequence
上述调用方式比较笨拙,不够优雅灵活,还需要手动写模板参数,其实看看0,1,2的序列,其实是从0到N-1的整数序列,c++14中正好提供了生成这种序列的机制:std::index_sequence,这里面有一系列的序列别名,我们这里更简便的使用index_sequence就能解决问题了,具体如下
https://zhuanlan.zhihu.com/p/490967621
/// Alias template index_sequencetemplate<size_t... _Idx>using index_sequence = integer_sequence<size_t, _Idx...>;/// Alias template make_index_sequencetemplate<size_t _Num>using make_index_sequence = make_integer_sequence<size_t, _Num>;/// Alias template index_sequence_fortemplate<typename... _Types>using index_sequence_for = make_index_sequence<sizeof...(_Types)>;
有了这个基础设施以后我们就可以这样写代码了:
https://blog.csdn.net/qq_51986723/article/details/127602490 std::index_sequence如何使用
#include <iostream>
#include <string>
#include <tuple>void foo(int a1, const char* a2, double a3) {// Do somethingstd::cout << a1 << std::endl;std::cout << a2 << std::endl;std::cout << a3 << std::endl;
}template <typename F, typename T, std::size_t... I>
void barImpl(F f, const T& t, std::index_sequence<I...>) {f(std::get<I>(t)...);
}template<typename F, typename T>
void bar(F f, const T& t) {barImpl(f, t, std::make_index_sequence<std::tuple_size<T>::value>());
}int main() {auto t = std::make_tuple(1, "Foo", 3.14);bar<decltype(foo), decltype(t)>(foo, t);return 0;
}
增加返回值
上面的虽然写起来比较简单了,但是没有返回值,我们可以采用decltype特性来解决。
#include <iostream>
#include <string>
#include <tuple>void foo(int a1, const char* a2, double a3) {// Do somethingstd::cout << a1 << std::endl;std::cout << a2 << std::endl;std::cout << a3 << std::endl;
}template <typename F, typename T, std::size_t... I>
auto barImpl(F f, const T& t, std::index_sequence<I...>) -> decltype(f(std::get<I>(t)...)){return f(std::get<I>(t)...);
}template<typename F, typename T>
auto bar(F f, const T& t) -> decltype(barImpl(f, t, std::make_index_sequence<std::tuple_size<T>::value>())) {return barImpl(f, t, std::make_index_sequence<std::tuple_size<T>::value>());
}
int main() {auto t = std::make_tuple(1, "Foo", 3.14);bar<decltype(foo), decltype(t)>(foo, t);return 0;
这样就使用任意的函数调用了,包括带返回值的和不带返回值的。
最终版本
-
封装一个万能调用类 +
-
直接传参
-
完美转发
将调用函数及参数封装进类中,在需要的时候调用Run一下就好了。
#include <iostream>
#include <string>
#include <tuple>template <typename Functor, typename... BoundArgs>
class OnceCallBack {
private:template <typename Functor1, typename TupleType1, std::size_t... I1>static auto RunImpl(Functor1 f, const TupleType1& t, std::index_sequence<I1...>) -> decltype(f(std::get<I1>(t)...)) {return f(std::get<I1>(t)...);}Functor* f_;std::tuple<BoundArgs...> t_;
public:OnceCallBack(Functor&& f, BoundArgs&&... t): f_(std::forward<Functor>(f)), t_(std::forward<BoundArgs>(t)...) {}auto Run() -> decltype(RunImpl(f_, t_, std::make_index_sequence<std::tuple_size<std::tuple<BoundArgs...>>::value>())) {return RunImpl(f_, t_, std::make_index_sequence<std::tuple_size<std::tuple<BoundArgs...>>::value>());}
};double foo_ret(double a1, char a2, const char* a3) {// Do somethingstd::cout << a1 << std::endl;std::cout << a2 << std::endl;std::cout << a3 << std::endl;return 1.2;
}int main() {// 函数模板参数类型编译器可以推导,但是类不行,所以这里需要很繁琐的传递参数类型OnceCallBack<decltype(foo_ret), decltype(1.0), decltype('c'), decltype("this is my test")> callback(std::move(foo_ret), 1.0, 'c', "this is my test");std::cout << callback.Run() << std::endl;
}
到这里,是不是已经很熟悉了。至此,一个最简单的base::Bind 方法就算实现完成了。
Chromium中的base::Bind
chromium中除了OnceCallBack还有RepeatingCallback,另外考虑的各种对象的生命周期问题,这样就涉及到指针传递,所以做的更为复杂,主要涉及的类包括:
-
BindStateBase
-
BindState
-
OnceCallBack
-
RepeatingCallback
-
Invoker
-
UnWrap
看到的也就是开头看到的源码
std::bind
C++11 bind绑定器,是一个函数模板 ,可以自动推演模板类型参数=> 返回的结果还是一个函数对象
bind占位符最多有20个参数
#include <iostream>
#include <typeinfo>
#include <string>
#include <memory>
#include <vector>
#include <functional>
#include <thread>
using namespace std;
using namespace placeholders;/*
C++11 bind绑定器 => 返回的结果还是一个函数对象
*/void hello(string str) { cout << str << endl; }
int sum(int a, int b) { return a + b; }
class Test
{
public:int sum(int a, int b) { return a + b; }
};
int main()
{//bind是函数模板 可以自动推演模板类型参数bind(hello, "hello bind!")();//返回的结果是绑定器,也就是函数对象 最后一个()表示调用函数对象的operator() cout << bind(sum, 10, 20)() << endl;cout << bind(&Test::sum, Test(), 20, 30)() << endl;//参数占位符 绑定器出了语句,无法继续使用//只是占位的作用,调用的时候就要传递参数了 //书写的时候使用多少个占位符,就是意味着用户调用的时候要传入几个参数bind(hello, placeholders::_1)("hello bind 2!");cout << bind(sum, placeholders::_1, placeholders::_2)(200, 300) << endl;//此处把bind返回的绑定器binder就复用起来了function<void(string)> func1 = bind(hello, _1);func1("hello china!");func1("hello shan xi!");func1("hello si chuan!");return 0;
}
/*** @brief Function template for std::bind.* @ingroup binders*/template<typename _Func, typename... _BoundArgs>inline typename_Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::typebind(_Func&& __f, _BoundArgs&&... __args){typedef _Bind_helper<false, _Func, _BoundArgs...> __helper_type;return typename __helper_type::type(std::forward<_Func>(__f),std::forward<_BoundArgs>(__args)...);}
---------------------------------------------------------------------------------------------------------------template<bool _SocketLike, typename _Func, typename... _BoundArgs>struct _Bind_helper: _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>{typedef typename decay<_Func>::type __func_type;typedef _Bind<__func_type(typename decay<_BoundArgs>::type...)> type;};
--------------------------------------------------template<typename _Functor, typename... _Bound_args>class _Bind<_Functor(_Bound_args...)>: public _Weak_result_type<_Functor>{typedef typename _Build_index_tuple<sizeof...(_Bound_args)>::__type_Bound_indexes;_Functor _M_f;tuple<_Bound_args...> _M_bound_args;// Call unqualifiedtemplate<typename _Result, typename... _Args, std::size_t... _Indexes>_Result__call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>){return std::__invoke(_M_f,_Mu<_Bound_args>()(std::get<_Indexes>(_M_bound_args), __args)...);}// Call as consttemplate<typename _Result, typename... _Args, std::size_t... _Indexes>_Result__call_c(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>) const{return std::__invoke(_M_f,_Mu<_Bound_args>()(std::get<_Indexes>(_M_bound_args), __args)...);}// Call as volatiletemplate<typename _Result, typename... _Args, std::size_t... _Indexes>_Result__call_v(tuple<_Args...>&& __args,_Index_tuple<_Indexes...>) volatile{return std::__invoke(_M_f,_Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...);}// Call as const volatiletemplate<typename _Result, typename... _Args, std::size_t... _Indexes>_Result__call_c_v(tuple<_Args...>&& __args,_Index_tuple<_Indexes...>) const volatile{return std::__invoke(_M_f,_Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...);}template<typename _BoundArg, typename _CallArgs>using _Mu_type = decltype(_Mu<typename remove_cv<_BoundArg>::type>()(std::declval<_BoundArg&>(), std::declval<_CallArgs&>()) );template<typename _Fn, typename _CallArgs, typename... _BArgs>using _Res_type_impl= typename result_of< _Fn&(_Mu_type<_BArgs, _CallArgs>&&...) >::type;template<typename _CallArgs>using _Res_type = _Res_type_impl<_Functor, _CallArgs, _Bound_args...>;template<typename _CallArgs>using __dependent = typenameenable_if<bool(tuple_size<_CallArgs>::value+1), _Functor>::type;template<typename _CallArgs, template<class> class __cv_quals>using _Res_type_cv = _Res_type_impl<typename __cv_quals<__dependent<_CallArgs>>::type,_CallArgs,typename __cv_quals<_Bound_args>::type...>;public:template<typename... _Args>explicit _Bind(const _Functor& __f, _Args&&... __args): _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...){ }template<typename... _Args>explicit _Bind(_Functor&& __f, _Args&&... __args): _M_f(std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...){ }_Bind(const _Bind&) = default;_Bind(_Bind&& __b): _M_f(std::move(__b._M_f)), _M_bound_args(std::move(__b._M_bound_args)){ }// Call unqualifiedtemplate<typename... _Args,typename _Result = _Res_type<tuple<_Args...>>>_Resultoperator()(_Args&&... __args){return this->__call<_Result>(std::forward_as_tuple(std::forward<_Args>(__args)...),_Bound_indexes());}// Call as consttemplate<typename... _Args,typename _Result = _Res_type_cv<tuple<_Args...>, add_const>>_Resultoperator()(_Args&&... __args) const{return this->__call_c<_Result>(std::forward_as_tuple(std::forward<_Args>(__args)...),_Bound_indexes());}#if __cplusplus > 201402L
# define _GLIBCXX_DEPR_BIND \[[deprecated("std::bind does not support volatile in C++17")]]
#else
# define _GLIBCXX_DEPR_BIND
#endif// Call as volatiletemplate<typename... _Args,typename _Result = _Res_type_cv<tuple<_Args...>, add_volatile>>_GLIBCXX_DEPR_BIND_Resultoperator()(_Args&&... __args) volatile{return this->__call_v<_Result>(std::forward_as_tuple(std::forward<_Args>(__args)...),_Bound_indexes());}// Call as const volatiletemplate<typename... _Args,typename _Result = _Res_type_cv<tuple<_Args...>, add_cv>>_GLIBCXX_DEPR_BIND_Resultoperator()(_Args&&... __args) const volatile{return this->__call_c_v<_Result>(std::forward_as_tuple(std::forward<_Args>(__args)...),_Bound_indexes());}};
placeholders 占位符:最多支持20个
相关文章:
chrome-base 如何实现一个BindOnce
考虑一个问题: worker_thread.task_runner()->PostDelayedTask(FROM_HERE, base::BindOnce(&Ref::Foo, ref, 1), base::Milliseconds(1000)); BindOnce 是如何实现的呢? 翻看源码:base\functional\bind.h 写的 非常简洁 // Bind a…...
代码随想录算法训练营day38
代码随想录算法训练营 —day38 文章目录 代码随想录算法训练营前言一、322. 零钱兑换二维dp数组 二、279.完全平方数二维dp数组 三、139. 单词拆分多重背包背包问题总结问题类型递推公式遍历顺序 前言 今天是算法营的第38天,希望自己能够坚持下来! 今日…...
对接DeepSeek
其实,整个对接过程很简单,就四步,获取key,找到接口文档,接口测试,代码对接。 获取 KEY https://platform.deepseek.com/transactions 直接付款就是了(现在官网暂停充值2025年2月7日࿰…...
【学术投稿-第六届新材料与清洁能源国际学术会议(ICAMCE 2025)】组织与结构:HTML中的<fieldset>与<legend>标签解析
官网:www.icceam.com 简介 第六届新材料与清洁能源国际学术会议(ICAMCE 2025)将于2025年2月21-23日在郑州隆重举行。清洁能源、新材料是当今工业发展中最重要、最有潜力的领域之一。而新型材料又是新能源的基础和保证。本会议主要围绕“清洁…...
网络安全行业的冬天
冬天已经来了,春天还会远吗?2022年10月28日,各个安全大厂相继发布了财报,纵观2022年前三季度9个月,三六零亏了19亿,奇安信亏了11亿,深信服亏了6亿,天融信亏了4亿,安恒亏了…...
PlantUml常用语法
PlantUml常用语法,将从类图、流程图和序列图这三种最常用的图表类型开始。 类图 基础语法 在 PlantUML 中创建类图时,你可以定义类(Class)、接口(Interface)以及它们之间的关系,如继承&#…...
【开源免费】基于SpringBoot+Vue.JS网上服装商城(JAVA毕业设计)
本文项目编号 T 185 ,文末自助获取源码 \color{red}{T185,文末自助获取源码} T185,文末自助获取源码 目录 一、系统介绍二、数据库设计三、配套教程3.1 启动教程3.2 讲解视频3.3 二次开发教程 四、功能截图五、文案资料5.1 选题背景5.2 国内…...
力扣LeetCode: 80 删除有序数组中的重复项Ⅱ
题目: 给你一个有序数组 nums ,请你 原地 删除重复出现的元素,使得出现次数超过两次的元素只出现两次 ,返回删除后数组的新长度。 不要使用额外的数组空间,你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件…...
Linux之kernel(4)netlink通信
Linux内核(04)之netlink通信 Author: Once Day Date: 2023年1月3日 一位热衷于Linux学习和开发的菜鸟,试图谱写一场冒险之旅,也许终点只是一场白日梦… 漫漫长路,有人对你微笑过嘛… 全系列文章可查看专栏: Linux内核知识_Once-Day的博客-…...
autMan奥特曼机器人-对接deepseek教程
一、安装插件ChatGPT 符合openai api协议的大模型均可使用此插件,包括chatgpt-4/chatgpt-3.5-turbo,可自定义服务地址和模型,指令:gpt,要求Python3.7以上,使用官方库https://github.com/openai/openai-pyt…...
Java 大视界 -- Java 大数据在智能政务中的应用与服务创新(78)
💖亲爱的朋友们,热烈欢迎来到 青云交的博客!能与诸位在此相逢,我倍感荣幸。在这飞速更迭的时代,我们都渴望一方心灵净土,而 我的博客 正是这样温暖的所在。这里为你呈上趣味与实用兼具的知识,也…...
RestTemplate Https 证书访问错误
错误信息 resttemplate I/O error on GET request for “https://21.24.6.6:9443/authn-api/v5/oauth/token”: java.security.cert.CertificateException: No subject alternative names present; nested exception is javax.net.ssl.SSLHandshakeException: java.security.c…...
自动化测试
import os import pyautogui# 将鼠标移动到屏幕坐标 (100, 100) 位置,移动时间为 1 秒 pyautogui.moveTo(100, 100, duration1)# 将鼠标从当前位置向右移动 50 像素,向下移动 50 像素,移动时间为 0.5 秒 pyautogui.moveRel(50, 50, duration0…...
【C编程问题集中营】使用数组指针时容易踩得坑
【C编程问题集中营】使用数组指针时容易踩得坑 文章目录 【C编程问题集中营】使用数组指针时容易踩得坑一、获取数组首地址二、应用场景举例2.1 正常场景2.2 异常场景 三、总结 一、获取数组首地址 一维数组的首地址即数组第一个元素的指针,常用的获取一维数组首地…...
【分布式理论8】分布式调用之:四种IO模型
文章目录 一. 四种IO模型1. 同步阻塞 IO(Blocking IO)2. 同步非阻塞 IO(Non-blocking IO)3. IO 多路复用(IO Multiplexing)4. 异步 IO(Asynchronous IO)在 RPC 中的作用5. 总结 选择…...
MySQL 库建表数量有限制吗?
问:MySQL 库建表数量有限制吗? 答:无限制 官方文档: MySQL has no limit on the number of databases. The underlying file system may have a limit on the number of directories. MySQL has no limit on the number of tabl…...
使用OpenGL自己定义一个button,响应鼠标消息:掠过、点击、拖动
button需要有一个外观 外观 大小跟随窗口改变,采用纯色背景、纯色文字 文字 大小跟随窗口改变 button需要获得鼠标消息 掠过 鼠标掠过时 button 出现阴影,鼠标掠过后 button 阴影消失 点击 点击后进入相应事件 拖动 改变图标所在位置 需要在g…...
基础入门-网站协议身份鉴权OAuth2安全Token令牌JWT值Authirization标头
知识点: 1、网站协议-http/https安全差异(抓包) 2、身份鉴权-HTTP头&OAuth2&JWT&Token 一、演示案例-网站协议-http&https-安全测试差异性 1、加密方式 HTTP:使用明文传输,数据在传输过程中可以被…...
【Python】元组
个人主页:GUIQU. 归属专栏:Python 文章目录 1. 元组的本质与基础概念1.1 不可变序列的意义1.2 元组与数学概念的联系 2. 元组的创建方式详解2.1 标准创建形式2.2 单元素元组的特殊处理2.3 使用 tuple() 函数进行转换 3. 元组的基本操作深入剖析3.1 索引操…...
深度求索与DeepSeek-R1:探索人工智能的新纪元
深度求索与DeepSeek-R1:探索人工智能的新纪元 引言 在当今快速发展的科技领域,尤其是人工智能(AI)方面,每隔一段时间就会出现一款革命性的产品或技术,彻底改变我们对这一领域的认知。2025年初,…...
java: framework from BLL、DAL、IDAL、MODEL、Factory using oracle
oracel 21c sql: -- 创建 School 表 CREATE TABLE School (SchoolId CHAR(5) NOT NULL,SchoolName NVARCHAR2(500) NOT NULL,SchoolTelNo VARCHAR2(8) NULL,PRIMARY KEY (SchoolId) );CREATE OR REPLACE PROCEDURE addschool(p_school_id IN CHAR,p_school_name IN NVARCHAR2,p…...
kafka生产端之架构及工作原理
文章目录 整体架构元数据更新 整体架构 消息在真正发往Kafka之前,有可能需要经历拦截器(Interceptor)、序列化器(Serializer)和分区器(Partitioner)等一系列的作用,那么在此之后又会…...
DeepSeek结合Langchain的基本用法
DeepSeek结合Langchain的基本用法 DeepSeek 基于Openai接口规范的Prompt应答Deepseek结合LangchainDeepSeek 基于langchain的结构化返回 DeepSeek 基于Openai接口规范的Prompt应答 首先我们需要先基于pip 安装 pip install openai最开始我们先熟悉如何使用openai的接口规范&a…...
Python与java的区别
一开始接触Python的时候,哔哩视频铺天盖地,看了很多人主讲的,要找适合自己口味的,各种培训机构喜欢在各种平台引流打广告,看了很多家,要么就是一个视频几个小时,长篇大论不讲原理只讲应用&#…...
win10 llamafactory模型微调相关① || Ollama运行微调模型
目录 微调相关 1.微调结果评估 2.模型下载到本地 导出转换,Ollama运行 1.模型转换(非常好的教程!) 2.Ollama 加载GGUF模型文件 微调相关 1.微调结果评估 【06】LLaMA-Factory微调大模型——微调模型评估_llamafactory评估-C…...
全国路网矢量shp数据(分不同类型分省份)
科研练习数据 全国路网矢量shp数据(分不同类型分省份) 有需要的自取 数据格式:shp(线) 数据包含类型:城市主干道、城市次干道、城市快速路、城市支路、高速公路、内部道路、人行道、乡村道路、自行车道路…...
RocketMq之Broker注册流程详解
1.前言 前面我也是写过一些关于broker注册到NameServer里的代码分析,但是总感觉写的比较简单,今天这篇的话,算是重新梳理一篇broker注册到NameServer中的代码,感兴趣的可以看下我前面写的几篇博客: 1.NameServer的主…...
关于精度话题的杂谈
“ 浮点值的存储、运算都可能会带来精度损失,了解精度损失背后的机制原因方便我们更好的了解什么情况下会发生精度损失、什么情况下精度损失较大,以及思考怎么避免或减少精度损失。” 01 杂谈 之前在CSDN上写过《关于float浮点值二进制存储和运算精度损失…...
AD域控粗略了解
一、前提 转眼大四,目前已入职上饶一公司从事运维工程师,这与我之前干的开发有着很大的差异,也学习到了许多新的知识。今天就写下我对于运维工作中常用的功能——域控的理解。 二、为什么要有域控,即域控的作用 首先我们必须要…...
emlog最新跨站脚本漏洞(CNVD-2025-01607、CVE-2024-13140)
EMLOG是一款轻量级开源博客和CMS建站系统,速度快、省资源、易上手,适合各种规模的站点搭建,基于PHPMySQL开发。 国家信息安全漏洞共享平台于2025-01-16公布该程序存在跨站脚本漏洞。 漏洞编号:CNVD-2025-01607、CVE-2024-13140 …...
DeepSeek-r1和O1、O3mini谁更强?
DeepSeek-r1和O1、O3mini谁更强? 题目:编写一个 js 程序,显示一个球在旋转的六边形内弹跳。球应该受到重力和摩擦力的影响,并且必须逼真地从旋转的墙壁上弹起 DeepSeek-r1 <!DOCTYPE html> <html> <body> &l…...
代码随想录_二叉树
二叉树 二叉树的递归遍历 144.二叉树的前序遍历145.二叉树的后序遍历94.二叉树的中序遍历 // 前序遍历递归LC144_二叉树的前序遍历 class Solution {public List<Integer> preorderTraversal(TreeNode root) {List<Integer> result new ArrayList<Integer&g…...
时序数据库:Influxdb详解
文章目录 一、简介1、简介2、官网 二、部署1、安装2、配置(1)用户初始化 三、入门(Web UI)1、加载数据(1)上传数据文件(2)代码接入模板 2、管理存储桶(1)创建…...
内存泄漏及检测办法
什么情况下会产生内存泄漏? 内存泄漏如何检测? 使用 valgrind 对象计数 基本思路: 在对象的构造函数中增加计数:每次创建一个对象时,增加一个计数。在对象的析构函数中减少计数:每次销毁一个对象时&…...
BiGRU双向门控循环单元多变量多步预测,光伏功率预测(Matlab完整源码和数据)
代码地址:BiGRU双向门控循环单元多变量多步预测,光伏功率预测(Matlab完整源码和数据) BiGRU双向门控循环单元多变量多步预测,光伏功率预测 一、引言 1.1、研究背景和意义 随着全球对可再生能源需求的不断增长,光伏…...
Leetcode 3448. Count Substrings Divisible By Last Digit
Leetcode 3448. Count Substrings Divisible By Last Digit 1. 解题思路2. 代码实现 题目链接:3448. Count Substrings Divisible By Last Digit 1. 解题思路 这一题的话我们走的是一个累积数组的思路。 首先,我们使用一个cache数组记录下任意段数字…...
青少年编程与数学 02-009 Django 5 Web 编程 03课题、项目结构
青少年编程与数学 02-009 Django 5 Web 编程 03课题、项目结构 一、项目结构项目根目录应用目录其他目录 二、项目设置Django 插件设置项目配置环境变量设置项目目录标记版本控制 三、Django 插件安装 Django 插件配置 Django 插件使用 Django 插件功能 四、扩展插件开发效率插…...
【玩转 Postman 接口测试与开发2_018】第14章:利用 Postman 初探 API 安全测试
《API Testing and Development with Postman》最新第二版封面 文章目录 第十四章 API 安全测试1 OWASP API 安全清单1.1 相关背景1.2 OWASP API 安全清单1.3 认证与授权1.4 破防的对象级授权(Broken object-level authorization)1.5 破防的属性级授权&a…...
UA-Track:不确定性感知端到端3D多目标跟踪
论文地址:https://arxiv.org/pdf/2406.02147 主页:https://liautoad.github.io/ua-track-website/ 3D多目标跟踪(MOT)在自动驾驶感知中起着至关重要的作用。最近基于端到端查询的跟踪器可以同时检测和跟踪对象,这在3D …...
Windows下AMD显卡在本地运行大语言模型(deepseek-r1)
Windows下AMD显卡在本地运行大语言模型 本人电脑配置第一步先在官网确认自己的 AMD 显卡是否支持 ROCm下载Ollama安装程序模型下载位置更改下载 ROCmLibs先确认自己显卡的gfx型号下载解压 替换替换rocblas.dll替换library文件夹下的所有 重启Ollama下载模型运行效果 本人电脑配…...
萌新学 Python 之字符串及字符串相关函数
字符串:单引号、双引号、三个单引号、三个双引号 字符串属于不可变的数据类型,一旦被定义,内存地址不变 name 张三 # 字符串赋值给name后,内存地址存储张三,地址不变 username 张三 # 张三去内存中找…...
【鸿蒙开发】第二十四章 AI - Core Speech Kit(基础语音服务)
目录 1 简介 1.1 场景介绍 1.2 约束与限制 2 文本转语音 2.1 场景介绍 2.2 约束与限制 2.3 开发步骤 2.4 设置播报策略 2.4.1 设置单词播报方式 2.4.2 设置数字播报策略 2.4.3 插入静音停顿 2.4.4 指定汉字发音 2.5 开发实例 3 语音识别 3.1 场景介绍 3.2 约束…...
Java | RESTful 接口规范
关注:CodingTechWork 引言 作为一名程序员,制定清晰、一致且高效的 RESTful 接口规范对于团队的开发效率和项目的长期维护至关重要。本文将详细介绍 RESTful 接口的设计理念、请求方法分类、核心规范,以及正确和错误的示例,帮助团…...
shell脚本控制——处理信号
Linux利用信号与系统中的进程进行通信。你可以通过对脚本进行编程,使其在收到特定信号时执行某些命令,从而控制shell脚本的操作。 1.重温Linux信号 Linux系统和应用程序可以产生超过30个信号。下表列出了在shell脚本编程时会遇到的最常见的Linux系统信…...
OpenGL学习笔记(十二):初级光照:投光物/多光源(平行光、点光源、聚光)
文章目录 平行光点光源聚光多光源 现实世界中,我们有很多种类的光照,每种的表现都不同。将光投射(Cast)到物体的光源叫做投光物(Light Caster)。 平行光/定向光(Directional Light)点光源(Point Light)聚光(Spotlight) 平行光 当一个光源处于很远的地…...
redis底层数据结构——整数集合
文章目录 定义内部实现升级升级的好处提升灵活性节约内存 降级总结 定义 整数集合(intset)是集合键的底层实现之一,当一个集合只包含整数值元素,并且这个集合的元素数量不多时,Redis就会使用整数集合作为集合键的底层…...
w198基于Springboot的智能家居系统
🙊作者简介:多年一线开发工作经验,原创团队,分享技术代码帮助学生学习,独立完成自己的网站项目。 代码可以查看文章末尾⬇️联系方式获取,记得注明来意哦~🌹赠送计算机毕业设计600个选题excel文…...
【JavaScript】《JavaScript高级程序设计 (第4版) 》笔记-Chapter2-HTML 中的 JavaScript
二、HTML 中的 JavaScript 将 JavaScript 插入 HTML 的主要方法是使用<script>元素。 <script>元素有下列 8 个属性。 async:可选。表示应该立即开始下载脚本,但不能阻止其他页面动作,比如下载资源或等待其他脚本加载。只对外部…...
【5】阿里面试题整理
[1]. 介绍一下ZooKeeper ZooKeeper是一个开源的分布式协调服务,核心功能是通过树形数据模型(ZNode)和Watch机制,解决分布式系统的一致性问题。 它使用ZAB协议保障数据一致性,典型场景包括分布式锁、配置管理和服务注…...
系统思考—自我超越
“人们往往认为是个人的能力限制了他们,但事实上,是组织的结构和惯性思维限制了他们的潜力。”—彼得圣吉 最近和一家行业隐形冠军交流,他们已经是领域第一,老板却依然要求:核心团队都要自我超越,攻坚克难…...