我有这样的问题:我有课Foo,如果有这个类的一些对象,
Foo a();
Run Code Online (Sandbox Code Playgroud)
我需要把这个对象放到两个不同的向量:
std::vector<Foo> vA, vB;
Run Code Online (Sandbox Code Playgroud)
如果a在改变vA应该改变了vB,载体vA和vB可以不同,但它们可以有相同的对象.我知道可以使用Boost,但我不能使用Boost.
我发现这个主题为什么处理排序数组比未排序数组更快?.并尝试运行此代码.而且我发现了奇怪的行为.如果我使用-O3优化标志编译此代码,则需要2.98605 sec运行.如果我用-O2它编译1.98093 sec.我尝试在同一环境中的同一台机器上运行此代码几次(5或6),我关闭所有其他软件(chrome,skype等).
gcc --version
gcc (Ubuntu 4.9.2-0ubuntu1~14.04) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Run Code Online (Sandbox Code Playgroud)
那么请你能解释一下为什么会这样吗?我阅读gcc手册,我看到-O3包括-O2.谢谢你的帮助.
PS添加代码
#include <algorithm>
#include <ctime>
#include <iostream>
int main()
{
// Generate data
const unsigned arraySize = 32768;
int data[arraySize];
for (unsigned …Run Code Online (Sandbox Code Playgroud) 我需要通过ssh在python上测试smth.我不想为每个测试做ssh连接,因为它很长,我写了这个:
class TestCase(unittest.TestCase):
client = None
def setUp(self):
if not hasattr(self.__class__, 'client') or self.__class__.client is None:
self.__class__.client = paramiko.SSHClient()
self.__class__.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.__class__.client.connect(hostname=consts.get_host(), port=consts.get_port(), username=consts.get_user(),
password=consts.get_password())
def test_a(self):
pass
def test_b(self):
pass
def test_c(self):
pass
def disconnect(self):
self.__class__.client.close()
Run Code Online (Sandbox Code Playgroud)
和我的跑步者
if __name__ == '__main__':
suite = unittest.TestSuite((
unittest.makeSuite(TestCase),
))
result = unittest.TextTestRunner().run(suite)
TestCase.disconnect()
sys.exit(not result.wasSuccessful())
Run Code Online (Sandbox Code Playgroud)
在这个版本中我得到错误TypeError: unbound method disconnect() must be called with TestCase instance as first argument (got nothing instead).那么在所有测试通过后我怎么能断断续续?最诚挚的问候.
我需要创建一个线程安全的映射,我的意思是每个值必须独立地互斥.例如,我需要能够得到map["abc"]和map["vf"]在2级不同的线程在同一时间.
我的想法是创建两个映射:一个用于数据,一个用于每个键的互斥:
class cache
{
private:
....
std::map<std::string, std::string> mainCache;
std::map<std::string, std::unique_ptr<std::mutex> > mutexCache;
std::mutex gMutex;
.....
public:
std::string get(std::string key);
};
std::string cache::get(std::string key){
std::mutex *m;
gMutex.lock();
if (mutexCache.count(key) == 0){
mutexCache.insert(new std::unique_ptr<std::mutex>);
}
m = mutexCache[key];
gMutex.unlock();
}
Run Code Online (Sandbox Code Playgroud)
我发现我无法创建从字符串到互斥锁的映射,因为没有复制构造函数std::mutex,我必须使用std::unique_ptr; 但是当我编译它时,我得到:
/home/user/test/cache.cpp:7: error: no matching function for call to 'std::map<std::basic_string<char>, std::unique_ptr<std::mutex> >::insert(std::unique_ptr<std::mutex>*)'
mutexCache.insert(new std::unique_ptr<std::mutex>);
^
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
我想使用yandex tank测试我的Web应用程序,我想测试注册,所以我需要发送这样的请求
标头
POST /registration HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 30
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: http://localhost:8080
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Referer: http://localhost:8080/registration
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,ru;q=0.6
Cookie: csrftoken=XJ3oheJb0SndHfNAH2lSV2AtKNxxuXdv; JSESSIONID=igq9ejgl10jirr4t73mpjblp
Run Code Online (Sandbox Code Playgroud)表格数据
login=abracadbra&password=brar
Run Code Online (Sandbox Code Playgroud)是否可以使用不同的登录字段发送这种请求?
我想std::array作为参数发送到我的虚函数
class Handler:
{
public:
template <std::size_t N>
virtual void handle(const std::array<char, N>& msg, std::vector<boost::asio::const_buffer>& buffers) = 0;
};
Run Code Online (Sandbox Code Playgroud)
但是gcc说templates may not be 'virtual'.那么我如何传递std::array给我的功能呢?
您好我有这样的模板:
......
<body onload='setInterval(function(){refresh()}, ${refreshPeriod} ); setClientTime();'>
<p>UserId: ${userId}</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我生成我的模板并将userId像4195578878989842599它一样显示时4 195 578 878 989 842 599,是否可以修复它?
c++ ×4
c++11 ×2
arrays ×1
freemarker ×1
gcc ×1
java ×1
load-testing ×1
optimization ×1
python ×1
ssh ×1
stl ×1
unit-testing ×1
vector ×1
yandex ×1
yandex-tank ×1