我的linux机器上的Htop在启动一个java程序/ JVM后显示了许多"进程".我知道JVM运行多个线程(用于实际程序,用于垃圾收集等).
但是为什么htop将它们列为具有不同pid的多个进程.这些流程究竟是什么?
问题:有一种方法可以在一台机器上运行相应的测试用例而在另一台机器上运行失败(详情如下).我认为代码有问题,导致它在一台机器上偶然工作.不幸的是我找不到问题.
请注意,std :: string和utf-8编码的使用是我没有实际影响的要求.使用C++方法会很好,但遗憾的是我找不到任何东西.因此使用C函数.
方法:
std::string firstCharToUpperUtf8(const string& orig) {
std::string retVal;
retVal.reserve(orig.size());
std::mbstate_t state = std::mbstate_t();
char buf[MB_CUR_MAX + 1];
size_t i = 0;
if (orig.size() > 0) {
if (orig[i] > 0) {
retVal += toupper(orig[i]);
++i;
} else {
wchar_t wChar;
int len = mbrtowc(&wChar, &orig[i], MB_CUR_MAX, &state);
// If this assertion fails, there is an invalid multi-byte character.
// However, this usually means that the locale is not utf8.
// Note that the default locale is …
Run Code Online (Sandbox Code Playgroud) 虽然我自己写的东西很容易写,但我经常想知道在iomanip
某个地方或某个地方是否有类似的东西.但是,我从未发现过有用的东西.理想情况下,它对区域设置很敏感(例如在德国,您将1,234,567.89写为1.234.567,89),因此非常优于手动构建逗号字符串.
所有测试用例都以某种方式包含<gtest/gtest.h>
并且<google/dense_hash_map>
无法为我构建.通常后者是间接包含但我可以重现这样的问题:
#include <gtest/gtest.h>
#include <google/dense_hash_map>
TEST(SparsehashTest, justPass) {
ASSERT_TRUE(true);
};
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Run Code Online (Sandbox Code Playgroud)
问题:
In file included from /usr/include/c++/5/tr1/functional:39:0,
from /usr/local/include/sparsehash/dense_hash_map:106,
from /usr/local/include/google/dense_hash_map:34,
from /home/me/xxx/test/SparsehashTest.cpp:6:
/usr/include/c++/5/tr1/tuple:130:11: error: redefinition of ‘class std::tuple< <template-parameter-1-1> >’
class tuple : public _Tuple_impl<0, _Elements...>
^
In file included from /home/me/xxx/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:697:0,
from /home/me/xxx/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:40,
from /home/me/xxx/third_party/googletest/googletest/include/gtest/gtest.h:58,
from /home/me/xxx/test/SparsehashTest.cpp:5:
/usr/include/c++/5/tuple:463:11: error: previous definition of ‘class std::tuple< <template-parameter-1-1> >’
class tuple : public _Tuple_impl<0, _Elements...>
Run Code Online (Sandbox Code Playgroud)
所以sparsehash包括/usr/include/c++/5/tr1/tuple …
我只是意识到提出问题是多么困难......希望我能给出两个都足够精确的例子来展示我的问题,并且足够短以免弄乱一切......至少可以编辑.
所以这就是我目前的情况.当然,我在逻辑/结构(以及无论如何命名方面)方面对它进行了一些修改,试图关注我问题的本质:
// MyClass deals with lists (actually several data structures) of the
// type MyType which should support different types and has to be
// efficiently dealt with. Templating seems just right here
class MyClass
{
...
void doSomething<class MyType>(vector<MyType> someList);
...
// At some point I have to extract elements of the type MyType.
// The extractor obviously depends on MyType but it is not possible to
// Create a general version that could use templates itself
// …
Run Code Online (Sandbox Code Playgroud) 我遇到了几个问题,其答案表明使用T*绝不是最好的主意.
虽然我已经大量使用RIIC,但我的代码中有一个特殊点,我使用T*.阅读几个自动指针,我找不到一个我会说我有使用它的明显优势.
我的情景:
class MyClass
{
...
// This map is huge and only used by MyClass and
// and several objects that are only used by MyClass as well.
HashMap<string, Id> _hugeIdMap;
...
void doSomething()
{
MyMapper mapper;
// Here is what I pass. The reason I can't pass a const-ref is
// that the mapper may possibly assign new IDs for keys not yet in the map.
mapper.setIdMap(&_hugeIdMap);
mapper.map(...);
}
}
Run Code Online (Sandbox Code Playgroud)
MyMapper
现在有一个HashMap<...>*
成员,根据对无关问题的问题的高度投票答案 - 从来不是一个好主意(在实例之前,映射器将超出范围MyClass …
这里和这里的答案几乎是我需要的.但是,我希望能够生成以下序列:
gen_seq<5, 2> // {0, 1, 3, 4}
gen_seq<3, 0> // {1, 2}
// optional behavior that would be useful for me:
gen_seq<4, 4> // {0, 1, 2, 3}
Run Code Online (Sandbox Code Playgroud)
在示例中,我使用gen_seq生成从0到N-1而没有I的序列.这不是强制性的,我也可以使用gen_seq,其中N是序列的长度,I是缺失的索引或其他变体.
我认为大多数问题已在相关问题中得到解答.然而,我无法真正地围绕如何将第二个参数的"保留一个"条件纳入其中.
理想情况下,我希望坚持使用c ++ 11功能并避免使用c ++ 14.但是,使用c ++ 14的优雅且特别易读的元素也可能非常有趣.
我的情况如下:有一些类MyList可能会在以后获得特定的实现.现在,像std :: vector这样的行为很好.
但是,我真的需要一种简单的方法来调用某种asString()/ toString()方法,因为我需要它在测试断言,调试输出等等.我看到的唯一选择是:
公共继承.我永远不会通过基指针删除这样的列表,因为永远不应该有任何基本指针.如果我这样做,反正将没有指针成员.但是,经验法则仍然指出:不要从stl容器继承.
某种"全局"(实际上在命名空间中)当然是以MyList的实例作为参数并为我做asString()魔术的方法.在这种情况下,MyList可能是std :: vector的简单typedef.
我不太喜欢那些选项.还有什么我没想到的吗?或者如果不是 - 我应该选择哪种方式?
c++ ×7
inheritance ×2
templates ×2
auto-ptr ×1
c ×1
c++11 ×1
compilation ×1
formatting ×1
g++ ×1
googletest ×1
htop ×1
java ×1
jvm ×1
localization ×1
numbers ×1
pointers ×1
process ×1
sparsehash ×1
stl ×1
utf-8 ×1