自从我在OS类中听到虚拟和物理内存概念的概念之后,这是一个非常基本的问题令人难以置信.现在我知道在加载时和编译时,虚拟地址和逻辑地址绑定方案是相同的,但在执行时它们是不同的.
首先,为什么在编译和加载时生成虚拟地址以及当我们应用&号运算符来获取变量,naive数据类型,用户定义类型和函数定义地址的地址时返回什么是有益的?
当OS这样做时,OS如何从虚拟地址到物理地址完全映射?这些问题都是出于好奇心而且我会喜欢考虑现代操作系统的一些好的和深刻的见解,"早期操作系统是怎么回事".我只是特定于C/C++,因为我对其他语言知之甚少.
我正在阅读Eckel的不变章节,并在Temporaries被解释的部分混淆了.我能得到的是,当我们将引用传递给函数时,编译器会创建一个临时的const对象,因此即使我们将引用作为参数传递,我们也无法修改它.
f(int &a){}
Run Code Online (Sandbox Code Playgroud)
现在我试着在网上查看其他一些Temporaries的参考资料并且被卡住了
http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage %2Fref%2Fcplr382.htm并且
所有临时值都是用C++编写的吗?
这促使我临时工具不仅仅是传递引用并在函数内部创建const对象.现在我可以从这两个链接中获得一些东西,但不能说我已经理解了临时工作的工作,功能和用途整个.如果有人可以解释临时的概念,那将会非常有用.提前致谢.
布鲁斯·埃克尔的原始例子是:
// Result cannot be used as an lvalue
class X {
int i;
public:
X(int ii = 0);
void modify();
};
X::X(int ii) { i = ii; }
void X::modify() { i++; }
X f5() {
return X();
}
const X f6() {
return X();
}
void f7(X& x) { // Pass by non-const reference
x.modify();
}
int main() {
f5() = X(1); // OK -- non-const return value
f5().modify(); …Run Code Online (Sandbox Code Playgroud) 给出的问题是http://www.spoj.com/problems/TOPOSORT/ 输出格式特别重要:
Print "Sandro fails." if Sandro cannot complete all his duties on the list.
If there is a solution print the correct ordering,
the jobs to be done separated by a whitespace.
If there are multiple solutions print the one, whose first number is smallest,
if there are still multiple solutions, print the one whose second number is smallest, and so on.
Run Code Online (Sandbox Code Playgroud)
我正在做的只是通过反转边缘来做dfs,即如果作业A在作业B之前完成,则存在从B到A的有向边.我通过对我创建的邻接列表进行排序并分别存储没有任何约束的节点来维护顺序,以便稍后以正确的顺序打印它们.使用了两个标志数组,一个用于标记已发现的节点,另一个用于标记已探索所有邻居的节点.
现在我的解决方案是http://www.ideone.com/QCUmKY(重要的功能是访问功能),并在运行正确的10个案例后给WA,所以很难弄清楚我在哪里做错了因为它运行对于我手工完成的所有测试用例.
我正在做这个特殊的问题AIBOHP并使用dp方法基于检查从1开始的长度为i的子串的末尾.尽管我的时间复杂度在O(n ^ 2)处很好但是空间占用太多因为我我正在获取RTE,如果我动态声明它或TLE,如果我将其声明为全局静态需要减少因为dp大小可以是6100*6100.任何建议如何为此目的优化我的下面的代码.
问题陈述是:
He now asks the doctors to insert the minimum number of characters needed to make S a palindrome. Help the doctors accomplish this task.
For instance, if S = "fft", the doctors should change the string to "tfft", adding only 1 character.
Run Code Online (Sandbox Code Playgroud)
我的代码是:
static int dp[6101][6101];
main()
{
int tc;
scanf("%d",&tc);
while(tc--)
{
char s[6102];
scanf("%s",s);
int len=strlen(s);
memset(dp,0,sizeof dp);
for(int i=1;i<len;i++)
for(int j=0,k=i;k<len;k++,j++)
dp[j][k]=(s[j]==s[k])?dp[j+1][k-1]:min(dp[j][k-1],dp[j+1][k])+1;
printf("%d\n",dp[0][len-1]);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用该命令安装rails
宝石安装导轨
在我的ubuntu 12.04上.我还使用用户名,密码和代理详细信息配置了apt.conf文件.然后执行此命令也会产生错误:
错误:执行gem时...(Net :: HTTPServerException)
407"需要代理身份验证"
如果我跑
sudo gem install rails
错误是:
错误:执行gem时...(Gem :: DependencyError)
无法解析依赖关系:treetop需要多语言(> = 0),多语言(> = 0.3.1); 链轮需要倾斜(!= 1.3.0,〜> 1.1)
我的本地宝石列表如下:
*LOCAL GEMS*
actionmailer(4.0.1)
actionpack(4.0.1)
activemodel(4.0.1)
activerecord(4.0.1)
activerecord-deprecated_finders(1.0.3)
activesupport(4.0.1)
arel(4.0.1)
atomic( 1.1.14)
bigdecimal(1.2.0)
builder(3.1.4)
bundler(1.3.5)
bundler-unload(1.0.2)
coffee-rails(4.0.1)
coffee-script(2.2.0)
coffee-script- source(1.6.3)
erubis(2.7.0)
execjs(2.0.2)
executable-hooks(1.2.6)
hike(1.2.3)
i18n(0.6.5)
io-console(0.4.2)
jbuilder(1.5. 2) json(1.8.1,1.7.7) 邮件(2.5.4)
jquery-rails(3.0.4)
1.8.1,1.7.7 mime-types(1.25)minitest(
4.7.5,4.3.2 )multi_json(1.8.2)
polyglot(0.3.3)
psych(2.0.0)
机架(1.5.2)
机架测试(0.6.2)
导轨(4.0.1)
铁路(4.0.1)
rake(
10.1.0,0.9.6 )rdoc(4.0.1,4.0.0,3.12.2)
rubygems-bundler(1.4.2)
rvm(1.11.3.8)
sass(3.2.12)
sass-rails(4.0.1)
sdoc(0.3.20)
sprockets(2.10.0)
sprockets-rails(2.0.1)
sqlite3( 1.3.8)
测试单元(2.0.0.0)
thor(0.18.1) …
我正在尝试为创建的Integer类重载二进制+:
const Integer operator+(const Integer& left,const Integer& right)
{
return Integer(left.i + right.i);
}
Run Code Online (Sandbox Code Playgroud)
和
const Integer operator+(const Integer& left,const Integer& right)
{
Integer tmp(left.i + right.i);
return tmp;
}
Run Code Online (Sandbox Code Playgroud)
现在我学到的是,在第一种情况下,创建一个临时的Integer对象并返回,在第二种情况下,使用构造函数调用然后复制然后调用析构函数来创建通常的对象.Ecekl对第一个问题所说的是编译器通过将对象直接构建到外部返回值的位置来利用这一点.我们从中推断出什么?我读到了返回值优化,但无法通过直接复制到位置事物来获得它的含义.
我在C++中有来自Eckel-Thining的以下代码行
Class Obj{
static int i,j;
public:
void f() const {cout<<i++<<endl;}
void f() const {cout<<i++<<endl;}
};
int Obj::i=47;
int Obj::j=11;
Run Code Online (Sandbox Code Playgroud)
现在它在Ecekl中为const成员函数编写,通过声明成员函数const,我们告诉编译器不要修改类数据.我理解在某些特定的情况下,比如可变const和显式地抛弃了这个指针的常量,我们可以废除它,但是这两个都没有发生,并且i ++和j ++正常工作.为什么会这样?
我非常天真地使用NS2并试图在NS2中实现UDP上的CBR.我写了以下代码:
set ns [new Simulator]
set tracefile [open out.tr w]
$ns trace-all $tracefile
set nf [open out.nam w]
$ns namtrace-all $nf
#should be "proc name args body"
#while executing
#"proc finish {}"
proc finish {}
{
global ns tracefile nf
$ns flush-trace
close $nf
close $tracefile
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
$ns simplex-link $n0 $n1 1Mb 10ms DropTail
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr[new Application/Traffic/CBR]
$cbr …Run Code Online (Sandbox Code Playgroud) 我正在尝试基于C的一些问题并陷入这个特殊问题.根据我的说法,old.out文件应该用scanf输入的任何内容写入,因为fprintf将输入分配给文件指针,但令我惊讶的是,我看到没有任何内容写入old.out,因为后面的while循环不是没有执行.这是怎么回事?是否与我对fprintf功能的误解有关?我已粘贴下面的代码.
#include<stdio.h>
main()
{
FILE *fp;
char a;
fp=fopen("old.out","w");
if(fp==0)
printf("File opening error");
else
{
for(scanf("%c",&a);a!=EOF;scanf("%c",&a))
fprintf(fp,"%c",a);
fclose(fp);
fp=fopen("old.out","r");
while(!feof(fp))
putchar(getc(fp));
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我遇到了一个代码片段,并认为它会调用copy-constructor,但相比之下,它只是调用了普通的构造函数.下面是代码
#include <iostream>
using namespace std;
class B
{
public:
B(const char* str = "\0")
{
cout << "Constructor called" << endl;
}
B(const B &b)
{
cout << "Copy constructor called" << endl;
}
};
int main()
{
B ob = "copy me";
return 0;
}
Run Code Online (Sandbox Code Playgroud)