问题几乎解释了这一切.我一直在想为什么Java有很好的,有组织的和集中的API文档,但C++库定义似乎分散在互联网上?
是否因为Sun在使Java API文档易于访问方面付出了一些努力?提前致谢.
我想从我的Java程序中使用linux命令行工具.我启动程序并使用Process类(http://download.oracle.com/javase/6/docs/api/java/lang/Process.html)获取输出:
/* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Process proc = Runtime.getRuntime().exec("octave");
BufferedReader reader =
new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedReader errorReader =
new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedWriter writer =
new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
int c;
while((c = proc.getInputStream().read()) != -1) {
System.out.print((char)c);
}
System.out.println("End");
}
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
GNU Octave,版本3.0.5版权所有(C)2008 John W. Eaton等.这是免费软件; 查看复制条件的源代码.绝对无保证; 甚至不适用于适销性或特定用途的适用性.有关详细信息,请键入"保修".
Octave配置为"i486-pc-linux-gnu".
有关Octave的更多信息,请访问http://www.octave.org.
如果您发现此软件有用,请提供帮助.有关更多信息,请访问 http://www.octave.org/help-wanted.html
报告错误(但首先请阅读 http://www.octave.org/bugs.html以了解如何编写有用的报告).
有关以前版本更改的信息,请键入"news".
奇怪的是,如果我在终端中运行八度音程,则正常输出如下:
:〜/ workspace/Console/src/c $ octave
GNU Octave,版本3.0.5版权所有(C)2008 John W. Eaton等.这是免费软件; …
请考虑以下代码,该代码使用两种略有不同的方法来检查_instance并在尚未设置时分配它.
class InstantiationTest
{
private Object _instance;
public void Method1() {
if(_instance == null) {
_instance = new Object();
}
}
public void Method2() {
_instance = _instance ?? new Object();
}
}
Run Code Online (Sandbox Code Playgroud)
VS或Resharper不断为我的显式空检查加下划线,并提示我使用null-coalescing运算符进行重构.
我不知道该编译器是否足够聪明来检测的情况下Method2()在那里_instance被重新分配给自己(实际上是一个NOP?),并改写Method2()成Method1().
我看到实际情况并非如此:
Test.Method1:
IL_0000: ldarg.0
IL_0001: ldfld UserQuery+Test._instance
IL_0006: brtrue.s IL_0013
IL_0008: ldarg.0
IL_0009: newobj System.Object..ctor
IL_000E: stfld UserQuery+Test._instance
IL_0013: ret
Run Code Online (Sandbox Code Playgroud)
与:
Test.Method2:
IL_0000: ldarg.0
IL_0001: ldarg.0
IL_0002: ldfld UserQuery+Test._instance
IL_0007: dup …Run Code Online (Sandbox Code Playgroud) 我有一个C#ClassLibrary,它包含一个对两个数字求和的函数:
namespace ClassLibrary1
{
public class Calculator
{
public int Calc(int i, int b) {
return i + b;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想从外部的其他C#应用程序加载此DLL.我怎样才能做到这一点?
我对所有标记的可读性(以及因此缩进)略显痴迷.
当我调用@Styles.Render("~/content/css")ASP.NET MVC4项目时,只有第一行保留了我的Razor模板的缩进.
这是输出:
<link href="/Content/css/ie.css" rel="stylesheet"/>
<link href="/Content/css/1140.css" rel="stylesheet"/>
<link href="/Content/css/screen.css" rel="stylesheet"/>
<link href="/Content/css/compatibility.css" rel="stylesheet"/>
Run Code Online (Sandbox Code Playgroud)
我希望所有生成的标记都具有与@Styles.Render()调用相同的缩进.
这很容易吗?如果是这样,怎么样?
asp.net indentation razor asp.net-mvc-4 bundling-and-minification
我首先定义一个大整数n:
Prelude> let n = 5705979550618670446308578858542675373983
Prelude> n :: Integer
5705979550618670446308578858542675373983
Run Code Online (Sandbox Code Playgroud)
接下来,我看着的行为s1和s2:
Prelude> let s1 = (sqrt (fromIntegral n))^2
Prelude> let s2 = (floor(sqrt(fromIntegral n)))^2
Prelude> s1 == fromIntegral n
True
Prelude> s1 == fromIntegral s2
True
Prelude> (fromIntegral n) == (fromIntegral s2)
False
Run Code Online (Sandbox Code Playgroud)
由于可能会丢弃任何小数部分,因此不期望最后2个表达式上的相等性.但是,我没想到平等是不及物的(例如n == s1, s1 == s2,但是n != s2.)
此外,floor尽管保留了40位有效数字,但似乎在整数部分上失去了精度.
Prelude> s1
5.70597955061867e39
Prelude> s2
5705979550618669899723442048678773129216
Run Code Online (Sandbox Code Playgroud)
测试减法时,这种丢失的精度变得明显:
Prelude> (fromIntegral n) - s1
0.0
Prelude> (fromIntegral …Run Code Online (Sandbox Code Playgroud) 我怎样才能有效地代表清单[0..] \\ [t+0*p, t+1*p ..]?
我已经定义:
Prelude> let factors p t = [t+0*p, t+1*p ..]
Run Code Online (Sandbox Code Playgroud)
我想高效地表示无限的名单是的差异[0..]和factors p t,而是使用\\从Data.List需要甚至中型列出了太多的记忆:
Prelude Data.List> [0..10000] \\ (factors 5 0)
<interactive>: out of memory
Run Code Online (Sandbox Code Playgroud)
我知道我可以代表之间的值t+0*p,并t+1*p用:
Prelude> let innerList p1 p2 t = [t+p1+1, t+p1+2 .. t+p2-1]
Prelude> innerList 0 5 0
[1,2,3,4]
Run Code Online (Sandbox Code Playgroud)
但是,反复计算和连接innerList增加间隔似乎很笨拙.
我能否有效地表示[0..] \\ (factors p t)不计算rem或mod每个元素?
math performance haskell functional-programming arithmetic-expressions
我注意到一些奇怪的事 我希望运行以下代码生成段错误,但事实并非如此.
void DeadlineTimeOut(const boost::system::error_code& pErrorCode, boost::thread* pThread)
{
std::cout << "Error code: #" << pErrorCode.value()
<< " Message: " << pErrorCode.message() << std::endl;
std::cout << "Thread Address = "
<< pThread << std::endl; // "sth. like 0x33aabc0"
pThread->interrupt();
pThread->join();
delete pThread;
delete pThread;
std::cout << "Stopped execution thread #"
<< pThread->get_id() << std::endl; // "{Not-any-thread}"
}
Run Code Online (Sandbox Code Playgroud)
那么,为什么双重删除可能?并且还要召集会员?我此刻有点困惑.
考虑这个简单的代码:
int foo = 4;
double d1 = sin (foo);
double d2 = foo * 0.1;
Run Code Online (Sandbox Code Playgroud)
当我用gcc编译它时,结果是预期的(即在数学上正确),即使sin()期望a double作为其参数.看来gcc已经隐含地foo投入了double.
这种隐式转换的可移植性如何,有哪些限制,我在哪里可以找到文档?
旁注:我知道C++编译器需要正确处理这样的转换.
有没有人知道如何在HTML5画布上顺序执行以下操作(使用javascript).
我觉得这很难做的原因是因为无法在脚本中创建暂停.任何帮助将不胜感激!