在下面,我没有定义类型doesntexist.
void myfunction(doesntexist argument)
{
}
Run Code Online (Sandbox Code Playgroud)
GCC 4.7.2说" error: variable or field ‘myfunction’ declared void"
我的问题是:编译器在这里想要将函数名称称为void而不是参数类型?
[ 编辑 ]
在downvoting之前,请注意此问题的答案与错误的顺序有关,并且-Wfatal-errors停止打印更直接相关的消息.这不仅仅是我对一个略微模糊的编译器消息.
我正在将一些代码移植到Windows,发现线程非常慢.Windows上的任务需要300秒(两个至强E5-2670 8核2.6ghz = 16核)和3.5秒(xeon E5-1607 4核3ghz).使用vs2012 express.
我有32个线程全部调用EnterCriticalSection(),弹出std :: stack的80字节作业,LeaveCriticalSection并做一些工作(总共250k个工作).
在每个关键部分调用之前和之后,我打印线程ID和当前时间.
(大致相同的Debug/Release,Debug需要更长的时间.我希望能够正确分析代码:P)
注释掉作业调用会使整个过程花费2秒钟(仍然超过linux).
我已经尝试了queryperformancecounter和timeGetTime,两者都给出了大致相同的结果.
AFAIK这个工作永远不会进行任何同步调用,但我不能解释减速,除非它确实如此.
我不知道为什么从堆栈复制并调用pop需要这么长时间.另一个令人困惑的事情是为什么对leave()的调用需要这么长时间.
任何人都可以推测为什么它运行如此缓慢?
我不会想到处理器的差异会带来100倍的性能差异,但它可能与双CPU有关吗?(必须在不同于内部核心的CPU之间进行同步).
顺便说一句,我知道std :: thread,但希望我的库代码能够与pre C++ 11一起使用.
编辑
//in a while(hasJobs) loop...
EVENT qwe1 = {"lock", timeGetTime(), id};
events.push_back(qwe1);
scene->jobMutex.lock();
EVENT qwe2 = {"getjob", timeGetTime(), id};
events.push_back(qwe2);
hasJobs = !scene->jobs.empty();
if (hasJobs)
{
job = scene->jobs.front();
scene->jobs.pop();
}
EVENT qwe3 = {"gotjob", timeGetTime(), id};
events.push_back(qwe3);
scene->jobMutex.unlock();
EVENT qwe4 = {"unlock", timeGetTime(), id};
events.push_back(qwe4);
if (hasJobs)
scene->performJob(job);
Run Code Online (Sandbox Code Playgroud)
和mutex类,删除linux #ifdef的东西......
CRITICAL_SECTION mutex; …Run Code Online (Sandbox Code Playgroud) 昨天我可以,今天我不能ctrl-c在终端杀死我的SDL应用程序.在SDL_Init调用之前,一切都按预期工作.之后,ctrl-c什么都不做.通话signal(SIGINT, SIG_DFL)不会改变这一点.我没有更新任何我能想到的东西,除了Nvidia的司机.这种情况发生在我几个月前编写的应用程序中.
有没有办法调试正在发生的事情?
[编辑]
即使这在此后停止工作SDL_Init(尽管行为正常gdb):
signal(SIGINT, exit);
raise(SIGINT);
Run Code Online (Sandbox Code Playgroud)
SDL1.2.15和SDL2也是如此(但过剩是好的).我正在使用gtx titan运行Fedora 18(x64),gcc 4.7.2,nvidia驱动程序331.2.
SDL_QUIT当我点击窗口上的关闭按钮时发生,但永远不会ctrl-c(从未使用过它 - SIGINT只会杀死应用程序).
[EDIT2]
这不是一贯可重复的,但很常见.有时候事先运行其他程序echo会增加ctrl-c工作机会.如果它不起作用,重复从不起作用.
经过一些进一步的测试后,似乎ctrl-c只有在SDL_INIT_TIMER传递给它时才停止工作SDL_Init.定时器子系统与信号有什么关系?
[EDIT3]
这是我的测试用例......
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <SDL2/SDL.h>
int main()
{
SDL_Window* window = NULL;
SDL_GLContext context;
fprintf(stderr, "Start");
usleep(3000000);
fprintf(stderr, ".\n");
//raise(SIGINT); //always works
struct sigaction old;
sigaction(SIGTERM, NULL, &old);
fprintf(stderr, "Init");
SDL_Init(SDL_INIT_VIDEO …Run Code Online (Sandbox Code Playgroud) image_load_store 扩展提供*vec4仅具有访问权限的加载/存储函数。例如,如果我有layout(rgba32f) uniform image2D myimage;,似乎我必须立即写入整个像素:
imageStore(myimage, coord, vec4(1,1,1,1));
Run Code Online (Sandbox Code Playgroud)
如果我只想将红色通道设置为1,我需要这样做:
vec4 pixel = imageLoad(myimage, coord);
pixel.r = 1;
imageStore(myimage, coord, pixel);
Run Code Online (Sandbox Code Playgroud)
这会因额外的读取而带来相当大的开销。
是否有一种机制可以用来仅写入特定通道?
类似的东西glColorMask,或者可能用不同的格式绑定数据,例如更大的GL_R32F image2D或imageBuffer?如果是这样,有哪些开销影响(例如转换/传输/缓存问题)?
正如您在图像中看到的那样,The Box不会滚动,而是在斜坡上滑动.

这是我如何在代码中创建框,
config = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(config);
broadphase = new btDbvtBroadphase();
solver = new btSequentialImpulseConstraintSolver();
bWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, config);
bWorld->setGravity(btVector3(0, -9.8f, 0));
// ...
btTransform t;
t.setIdentity();
t.setOrigin(btVector3(position.x, position.y, position.z));
btBoxShape* box = new btBoxShape(btVector3(size.x, size.y, size.z));
btVector3 inertia(0, 0, 0);
float mass = 10.f;
box->calculateLocalInertia(mass, inertia);
btMotionState* mState = new btDefaultMotionState(t);
btRigidBody::btRigidBodyConstructionInfo cInfo(mass, mState, box);
//cInfo.m_restitution = 0.4f;
//cInfo.m_friction = 0.5f;
btRigidBody* body = new btRigidBody(cInfo);
//body->setLinearFactor(btVector3(1,1,0));
//body->setAngularFactor(btVector3(0,0,1));
m_impl->bWorld->addRigidBody(body);
Run Code Online (Sandbox Code Playgroud)
我尝试了摩擦和其他参数,但结果是一样的.让我知道我在这里做错了什么.
我想在给定主键的查询集中找到相邻项,如此处所示。但是我希望这对于任何给定的查询集都有效,但我尚未为自己设置顺序。如何找到查询集的当前排序__gt并进行__lt过滤?
例如:
queryset = MyModel.objects.all().order_by('some_field')
next_obj = get_next(queryset, after_pk, 10)
...
def get_next(queryset, pk, n):
#ordering is unknown here
obj = queryset.get(pk=pk)
field = queryset.get_order_by_field_name() #???
return queryset.filter(**{field+'__gt': getattr(obj, field)})[:n]
Run Code Online (Sandbox Code Playgroud)
似乎 django 或 sqlite 数据库正在以微秒精度存储日期时间。但是,当将时间传递给 javascript 时,该Date对象仅支持毫秒:
var stringFromDjango = "2015-08-01 01:24:58.520124+10:00";
var time = new Date(stringFromDjango);
$('#time_field').val(time.toISOString()); //"2015-07-31T15:24:58.520Z"
Run Code Online (Sandbox Code Playgroud)
注意58.520124是现在58.520。
例如,当我想为日期时间小于或等于现有对象(即MyModel.objects.filter(time__lte=javascript_datetime))的所有对象创建查询集时,这就会成为一个问题。通过截断微秒,对象不再出现在列表中,因为时间不相等。
我该如何解决这个问题?是否有支持微秒精度的日期时间 javascript 对象?我是否可以将数据库中的时间截断为毫秒(我几乎auto_now_add到处都在使用)或要求以降低的精度执行查询?
Ctrl-C/SIGTERM/SIGINT 似乎被 tkinter 忽略。通常可以通过回调再次捕获它。这似乎不起作用,所以我想我应该在另一个线程中运行 tkinter ,因为它的mainloop() 是一个无限循环和 block。实际上我也想这样做以在单独的线程中从标准输入读取。即使在此之后,Ctrl-C 仍然不会被处理,直到我关闭窗口。这是我的 MWE:
#! /usr/bin/env python
import Tkinter as tk
import threading
import signal
import sys
class MyTkApp(threading.Thread):
def run(self):
self.root = tk.Tk()
self.root.mainloop()
app = MyTkApp()
app.start()
def signal_handler(signal, frame):
sys.stderr.write("Exiting...\n")
# think only one of these is needed, not sure
app.root.destroy()
app.root.quit()
signal.signal(signal.SIGINT, signal_handler)
Run Code Online (Sandbox Code Playgroud)
结果:
这是怎么回事?如何让终端中的 Ctrl-C 关闭应用程序?
更新:按照建议添加 poll,在主线程中工作,但在另一个线程中启动时没有帮助......
class MyTkApp(threading.Thread):
def poll(self):
sys.stderr.write("poll\n")
self.root.after(50, self.poll) …Run Code Online (Sandbox Code Playgroud) 使用web.whatsapp.de时,可以看到收到的图片的链接可能如下所示:
blob:https://web.whatsapp.com/3565e574-b363-4aca-85cd-2d84aa715c39
Run Code Online (Sandbox Code Playgroud)
如果将链接复制到地址窗口,它将打开图像,但是 - 如果省略"blob" - 它将只打开一个新的web whatsapp窗口.
我正在尝试下载此链接显示的图像.
但是使用常见的技术,例如使用request,urllib.request甚至BeautifulSoup总是在某一点上挣扎:url开头的"blob"会抛出错误.
这些答案使用Python从Blob URL下载文件 将显示错误
URLError: <urlopen error unknown url type: blob>
Run Code Online (Sandbox Code Playgroud)
或错误
InvalidSchema: No connection adapters were found for 'blob:https://web.whatsapp.com/f50eac63-6a7f-48a4-a2b8-8558a9ffe015'
Run Code Online (Sandbox Code Playgroud)
(使用BeatufilSoup)
使用原生方法,如:
import requests
url = 'https://web.whatsapp.com/f50eac63-6a7f-48a4-a2b8-8558a9ffe015'
fileName = 'test.png'
req = requests.get(url)
file = open(fileName, 'wb')
for chunk in req.iter_content(100000):
file.write(chunk)
file.close()
Run Code Online (Sandbox Code Playgroud)
只会导致与使用BeautifulSoup相同的错误.
我在Python中使用Selenium控制Chrome,但是我无法使用提供的链接正确下载图像.
How can I combine the following two functions into one? Is there something similar to std::forward, but for ranges?
#include <ranges>
#include <vector>
#include <algorithm>
template<class RangeIn, class RangeOut>
void moveOrCopy(RangeIn& from, RangeOut& to)
{
std::ranges::copy(from, std::back_inserter(to));
}
template<class RangeIn, class RangeOut>
requires std::is_rvalue_reference_v<RangeIn&&>
void moveOrCopy(RangeIn&& from, RangeOut& to)
{
std::ranges::move(from, std::back_inserter(to));
}
void test()
{
std::vector<int> a, b;
moveOrCopy(a, b); // copy
moveOrCopy(std::move(a), b); // move
}
Run Code Online (Sandbox Code Playgroud)
There is std::ranges::forward_range, but that's related to forward_iterator, not …
c++ ×4
c ×3
django ×2
javascript ×2
opengl ×2
python ×2
signals ×2
bullet ×1
c++20 ×1
django-orm ×1
game-engine ×1
game-physics ×1
gcc ×1
glsl ×1
image-unit ×1
linux ×1
precision ×1
sdl ×1
selenium ×1
std-ranges ×1
time ×1
tkinter ×1
url ×1
whatsapp ×1
windows ×1