-(void)test
{
int i;
for (i=0;i < 1000000;i++)
{
//do lengthly operation
}
}
Run Code Online (Sandbox Code Playgroud)
如何防止其GUI冻结?
我正在使用以下列ExecuteScalar:
cmd.commandtext = "select rodeuser from customer_db_map";
string rodecustomer = cmd.executescalar;
Run Code Online (Sandbox Code Playgroud)
但我需要获得多个专栏,例如:
cmd.commandtext = "select rodeuser,username,password from customer_db_map";
Run Code Online (Sandbox Code Playgroud)
我需要字符串中的每一列:
string rodecustomer = cmd.ExecuteScalar();
string username= cmd.ExecuteScalar();
string password = cmd.ExecuteScalar();
Run Code Online (Sandbox Code Playgroud)
但这是不可能的.这是如何实现的?
例如:
var s = '3+3';
s.replace(/([\d.]+)([\+\-)([^,]*)/g,
function(all, n1, operator, n2) {
r = new Number(n1) ??? new Number(n2);
return r;
}
);
Run Code Online (Sandbox Code Playgroud)
注意:不使用 eval()
任何人都可以帮我指出我的程序中的错误是什么?
在此先感谢,kingsmasher1
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
#include <errno.h>
typedef struct msgbuf {
long mtype; /* message type, must be > 0 */
char mtext[15]; /* message data */
} msgbuf;
int main() {
key_t key;
int msqid, pid, length;
msgbuf buf;
msqid=msgget(IPC_PRIVATE,IPC_CREAT);
if(msqid==-1){
perror("msgget failed");
return;
}
else {
printf("msgget succeeded. ID:%u",msqid);
}
pid=fork();
if(pid==-1) {
perror("fork failed\n");
}
buf.mtype=1;
strcpy(buf.mtext, "This is a test message");
length=sizeof(buf.mtext);
if(msgsnd(msqid,&buf,length,0)!=0) {
perror("msgsnd failed:\n");
} …Run Code Online (Sandbox Code Playgroud) !isalpha( str[first] ) ? ( return isPalindrome( str, ++first, last ) ) : return isPalindrome( str, first, --last ) ;
Run Code Online (Sandbox Code Playgroud)
我收到语法错误.
#include <iostream>
using namespace std;
int main()
{
const int kiNum = 100;
int* ptr = const_cast<int*>(&kiNum);
*ptr = 200;
cout<<"kiNum: "<<kiNum; // The value still prints 100 on the console??
return 0;
}
output:
kiNum = 100
Run Code Online (Sandbox Code Playgroud)
在上面的代码片段中,我试图在const_cast之后更改const整数的值,然后更改地址处的值,但控制台仍然打印旧值(我使用的是visual studio 2012)
我正在编写一个图形引擎作为大学的任务,并且最近尝试优化我的部分代码,但是优化似乎会减慢它的速度.
代码的这一特定部分处理2D Lindenmayer系统并将它们转换为"line2D"对象列表,这些对象可以由程序的另一部分处理成图像.
在这样做时,它使用sin和cos来计算下一个点的坐标,并且因为sin和cos是浮点运算,我认为这些将是时间密集的,尤其是在更复杂的lindenmayer系统中.所以我创建了一个对象类"cossinlist",它从.txt文件中导入cos和sin的值,用于0到359度之间的每个整数角度(转换为rad)到两个名为"coslist"和"sinlist"的地图作为关键.这样我在处理包含小数部分的角度时只需要执行实际的触发器.
然后我决定用一个相对密集的系统来测量执行时间和优化(没有它)(通过评论它):使用它,引擎在33.4016秒内生成图像,没有它只需要25.3686秒.这是一个实质性的差异,但不是预期的方式.我做了更多的测试,他们都给出了相似的差异比例,所以现在我想知道......是什么导致了这种差异?
功能:
img::EasyImage LSystem2D(const unsigned int size, const ini::DoubleTuple & backgroundcolor, LParser::LSystem2D & System, const ini::DoubleTuple & color)
{
CosSinList cossinlist;
std::string string;
Lines2D Lines;
double origin = 0;
Point2D currentpos(origin, origin);
Point2D newpos(origin, origin);
std::stack<Point2D> savedpositions;
double currentangle = System.get_starting_angle();
std::stack<double> savedangles;
const img::Color linecolor(color.at(0)*255,color.at(1)*255,color.at(2)*255);
const img::Color BGcolor(backgroundcolor.at(0)*255,backgroundcolor.at(1)*255,backgroundcolor.at(2)*255);
string = ReplaceLsystem(System, (System.get_initiator()), (System.get_nr_iterations()));
bool optimizedangle = false;
if(System.get_angle() == rint(System.get_angle()) && (System.get_starting_angle() == rint(System.get_starting_angle()))
{
optimizedangle = true;
}
for(char& c : string)
{
if(currentangle …Run Code Online (Sandbox Code Playgroud) c++ ×3
c ×1
c# ×1
c++11 ×1
cocoa ×1
conditional ×1
javascript ×1
linux ×1
macos ×1
operators ×1
optimization ×1