草庐IT

avcodec_find_encoder

全部标签

如何使用strspn模仿std :: string的find_first_not_of

我正在尝试创建类似于std::String的自定义字符串类。而且我在实现“find_first_not_of”时遇到了麻烦。这是我的测试代码#includeclassString{private:char*m_data;intm_length;char*alloc(intsize);intlength()const{returnm_length;}intsize()const{returnm_length;}constchar*c_str()const{returnm_data;}public:String(constchar*str=0);intfind_first_not_of(const

java - C++/ java : Efficiently find a set in the collection containing given value

假设我们有一组互斥集合{A,B,C,D}其中A={1,2,3},B={4,5,6},C={7,8,9},D={10,11,12}给定一个值Z,例如3,我希望它返回集合A的索引,因为A的成员是3。问题是我如何使用C++或JAVA高效地完成它。我当前的解决方案:将A、B、C、D作为HashSet(或C++中的unordered_set)存储在容器中并循环遍历每个集合,直到包含Z找到了。问题在于容器中存储的集合数量的复杂度为O(n)。有什么方法(或任何数据结构来存储这些集合)比O(n)更快地做到这一点吗? 最佳答案 您可以创建一个将值映射

c++ - std::search 是否有一个函数类似于 std::count 对 std::find 的函数?

如果标题听起来很奇怪,这里有另一种解释:如果我有一个范围a,我想计算另一个范围b在范围a中出现了多少次,是否有一个std::函数来做呢?如果不是,是否有一种简单的方法(当然我可以使用std::search手动循环-我说的是更优雅的东西)? 最佳答案 我认为您需要构建自己的。以下是我想到的实现方式。templatesize_tsubsequence_count(Iterator1haystack_begin,Iterator1haystack_end,Iterator2needle_begin,Iterator2needle_end)

c++ - 为什么 std::map find() 没有声明为 noexcept?

C++14标准定义std::map的find()成员函数如下:iteratorfind(constkey_type&x);const_iteratorfind(constkey_type&x)const;为什么这些函数没有定义为noexcept?内部可能出现什么问题,这将需要抛出异常或产生未定义的行为(除了找不到元素,在这种情况下函数返回end迭代器并且无论如何都不需要抛出异常)? 最佳答案 find()基于map的Compare()方法,这可能会引发异常(想象一下复杂键可能不正确的情况).因此,我们不能确定find()不会引发异常

c++ - avcodec_open2 方法中的 ffmpeg 内存泄漏

我开发了一个处理实时视频流的应用程序。问题是它应该作为服务运行,随着时间的推移,我注意到一些内存增加了。当我使用valgrind检查应用程序时-它没有发现任何与泄漏相关的问题。所以我用谷歌配置文件工具检查了它。这是运行大约6小时后的结果(从最新的转储中减去第一个转储):30.035.7%35.7%30.035.7%av_malloc28.934.4%70.2%28.934.4%av_reallocp24.529.2%99.4%24.529.2%x264_malloc当我检查图表上的内存时,我发现这些分配与avcodec_open2相关。客户端代码为:`g_EncoderMutex.lo

c++ - 为什么 set::find 不是模板?

使用来自的模板函数你可以这样做structfoo{intbar,baz;};structbar_less{//comparefoowithfoobooloperator()(constfoo&lh,constfoo&rh)const{returnlh.bar//comparesomeTwithfoobooloperator()(Tlh,constfoo&rh)const{returnlh//comparefoowithsomeTbooloperator()(constfoo&lh,Trh)const{returnlh.barbaz;}在std::set类似find的方法你必须传递一个s

c++ - 我如何构造一个仿函数以用于像 boost 的 brent_find_minima 这样的算法?

我试图理解为什么不能将具有构造函数的仿函数传递给算法,而没有构造函数的仿函数却可以。对于算法boost-brent_minima。当仿函数没有构造函数时,示例代码工作正常:#includestructfuncdouble{doubleoperator()(doubleconst&x){//return(x+3)*(x-1)*(x-1);//(x+3)(x-1)^2}};intbits=std::numeric_limits::digits;std::pairr=brent_find_minima(funcdouble(),-4.,4./3,bits);std::cout.precisi

c++ - m.find(...) == m.end() - 使用的是 iterator 或 const_iterator

std::mapfind/end都提供const_iterator和迭代器,例如iteratorend();const_iteratorend()const出于好奇,如果我有一个std::map,它将在这里被调用/比较,一个迭代器或一个const_iterator?:if(m.find(key)!=m.end()){...}我应该关心吗? 最佳答案 如果m是const,则返回一个const_iterator;否则将返回一个迭代器。如果您所做的只是测试map中是否存在某个元素,那么使用哪个元素并不重要。

c++ - 如何 std::find 使用比较对象?

我对std::find的接口(interface)感到困惑。为什么它不用Compare对象来告诉它如何比较两个对象?如果我可以传递一个Compare对象,我可以使下面的代码工作,我想在其中按值进行比较,而不是直接比较指针值:typedefstd::vectorVec;Vecvec;std::string*s1=newstd::string("foo");std::string*s2=newstd::string("foo");vec.push_back(s1);Vec::const_iteratorfound=std::find(vec.begin(),vec.end(),s2);//

c++ - 理论上,find_end 是可并行化的吗?

我目前正在研究open-stdproposal为我正在处理的项目带来并行功能,但我遇到了find_end的障碍。现在find_end可以描述为:Analgorithmthatsearchesforthelastsubsequenceofelements[s_first,s_last)intherange[first,last).Thefirstversionusesoperator==tocomparetheelements,thesecondversionusesthegivenbinarypredicatep.它的要求由cppreference列出.现在我并行化find/findi