在Android中,当我在服务中创建runnable并运行它时,虽然我意识到它在自己的线程中运行,但这个线程是否在某种程度上是UI线程的一部分?换句话说,如果runnable执行了一个很长的过程,它会影响用户界面吗?
编辑:
private class SomeRunnable implements Runnable
{
@Override
public void run()
{
try
{
}
}
}
SomeRunnable runnable = new SomeRunnable();
(new Handler()).postDelayed(runnable, 1000);
Run Code Online (Sandbox Code Playgroud) 我经常这样做:
$ gitk &
Run Code Online (Sandbox Code Playgroud)
启动一个程序(就像gitk
在这种情况下,但哪个无关紧要)并返回到 shell 提示符以继续在同一个 shell 中工作。在你已经写完之后你会怎么做
$ gitk
Run Code Online (Sandbox Code Playgroud)
没有&
?是否有像^z
那样的组合键,可以将进程置于后台但不会中断它?
如何在Windows上将mercurial命令行的语言永久更改为英语?按照本答案中的描述设置LANG环境变量可以暂时帮助一个命令窗口,但语言是否可以在mercurial.ini(或hgrc)中以某种方式设置或以其他方式设置?
这背后的原因:德国的mercurial输出被打破,所有特殊字符(Umlaute等)都没有正确显示.
我正在制作一个简单的2列布局的网站.列将具有不同的高度(一个高于另一个)和动态高度(每个页面的内容不同).两列的背景颜色应该向下延伸到最长列内容的最低点.
对于你们中的视觉学习者,CSS-Tricks有一些很好的插图
我正在使用One True Layout Method,在同一个CSS-Tricks页面上提到了大约一半.
这是相关的编码
HTML
<a href="#area1">Go To Section 1</a>
<a href="#area2">Go To Section 2</a>
<a href="#area3">Go To Section 3</a>
<div id="hold">
<div id="col1">
Content Column 1
</div>
<div id="col2">
Content Column 2
<h2 id="area1">Section 1</h2>
<img src="http://placehold.it/100x750" alt=" placehold img" />
<h2 id="area2">Section 2</h2>
<img src="http://placehold.it/100x750" alt=" placehold img" />
<h2 id="area3">Section 3</h2>
<img src="http://placehold.it/100x750" alt=" placehold img" />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
#hold{
height:100%;
overflow-y:hidden;
}
#col1, #col2{
padding-bottom:100000px; …
Run Code Online (Sandbox Code Playgroud) 使用gcc 4.7.2(mingw)编译以下代码
#include <unordered_map>
#include <tuple>
struct test
{
test() =default;
private:
test(test const&) =delete;
};
int main()
{
std::unordered_map<char, test> map;
map.emplace(
std::piecewise_construct,
std::forward_as_tuple('a'),
std::forward_as_tuple()
);
}
Run Code Online (Sandbox Code Playgroud)
如果我改变了拷贝构造函数test
从test(test const&) =delete;
到test(test const&) =default;
然而,模板错误呕吐,似乎抱怨const test&
不被转换为test
(文字在这里).不应该工作吗?或者如果没有,他们是否应该给出错误?
我为汇编翻译编写了一个虚拟机语言,用于我正在学习的计算机系统课程(使用nand2tetris课程).我最初是用Python编写的,但是因为我正在学习D,我以为我会翻译它.D在语法上与Python非常接近,所以它并不太难.我认为D,作为一种性能语言并且已经编译,至少和Python一样快,在大文件上,会快得多.但事实恰恰相反!尽管算法相同,但当我构造一个非常大的文件进行编译时,D的执行速度仍然比python略慢.在大约500000行的文件上,python一直需要大约2.6秒完成,而D一直占用大约3.这不是一个巨大的差距,但值得注意的是python会更快.
我不想暗示我天真地认为python实际上比D总体更快; 然而,在这种情况下,至少看起来D不是直观地更快.我很感激我的D代码中可能的性能下降的一些输入.我认为瓶颈可能是IO操作,但我不确定.
源代码如下.细节并不重要; 分配了一些汇编语言模板,然后通过虚拟机语言进行线性传递,将每条指令转换为等效的汇编代码块.
编辑:在使用D代码重新编译之后dmd -O -release -inline -m64
,D在输入上以2.20秒的时间输出胜利者.然而,问题仍然存在,为什么几乎相同的代码,D似乎比python执行速度慢.
编辑2:使用下面的建议,我从使用简单的字符串列表切换到使用a appender!string()
,并将时间改进了显着的数量.但值得一提的是,如果你有一堆字符串appender
,请不要使用如下命令将它们写入文件:
auto outputfile = File("foo.txt","w");
foreach(str; my_appender.data)
outputfile.write(str);
Run Code Online (Sandbox Code Playgroud)
而是写一些类似于:
auto outputfile = File("foo.txt","w");
outputfile.write(my_appender.data);
Run Code Online (Sandbox Code Playgroud)
第二个例子比使用简单的例子提供了小的性能提升string[]
.但是使用第一个给我带来了巨大的性能损失,使执行时间翻了一番.
更改为a appender!string()
,上述大文件的编译花费了大约2.75秒(对于Python的2.8),其中原始版本大约需要3.执行此操作,并使用优化标记dmd
,总编译时间为1.98
秒!:)
蟒蛇:
#!/usr/bin/python
import sys
operations_dict = {"add":"+", "sub":"-",
"and":"&", "or":"|",
"not":"!", "neg":"-",
"lt":"JLT", "gt":"JGT",
"eq":"JEQ", "leq":"JLE",
"geq":"JGE"}
vars_dict = {"this":("THIS","M"),
"that":("THAT","M"),
"argument":("ARG","M",),
"local":("LCL","M",),
"static":("f.%d","M",),
"temp":("TEMP","A",)}
start = "@SP\nAM=M-1\n"
end = "@SP\nM=M+1\n"
binary_template = start + "D=M\n\ …
Run Code Online (Sandbox Code Playgroud) 谁知道怎么从罐子里装Zul?我有一个包含祖尔的图书馆项目.目前我使用createComponents(String uri,Component parent,Map arg),但我不知道或不能在jar中引用uri.
我现在用:
public static Component createComponentsFromJar(final String path, final Component parent, final Map<?,?> arg) throws IOException {
final InputStream resourceAsStream = ComponentHelper.class.getClassLoader().getResourceAsStream(path);
final PageDefinition pageDefinition = Executions.getCurrent().getPageDefinitionDirectly(new InputStreamReader(resourceAsStream), "zul");
resourceAsStream.close();
return Executions.createComponents(pageDefinition, parent, arg);
}
Run Code Online (Sandbox Code Playgroud)
有没有人知道这种创建新页面的方法有什么问题?一些绑定问题还是有些问题?
我正在尝试使用mef创建一个POC,我需要在一个准备好运行的项目中动态加载dll,为此我创建了一个控制台应用程序项目和一个类库
项目.
控制台应用程序项目的代码如下 -
namespace MefProjectExtension
{
class Program
{
DirectoryCatalog catalog = new DirectoryCatalog(@"D:\MefDll", "*.dll");
[Import("Method1", AllowDefault = true, AllowRecomposition = true)]
public Func<string> method1;
static void Main(string[] args)
{
AppDomainSetup asp = new AppDomainSetup();
asp.ShadowCopyFiles = "true";
AppDomain sp = AppDomain.CreateDomain("sp",null,asp);
string exeassembly = Assembly.GetEntryAssembly().ToString();
BaseClass p = (BaseClass)sp.CreateInstanceAndUnwrap(exeassembly, "MefProjectExtension.BaseClass");
p.run();
}
}
public class BaseClass : MarshalByRefObject
{
[Import("Method1",AllowDefault=true,AllowRecomposition=true)]
public Func<string> method1;
DirectoryCatalog catalog = new DirectoryCatalog(@"D:\MefDll", "*.dll");
public void run()
{
FileSystemWatcher sw = new FileSystemWatcher(@"D:\MefDll", …
Run Code Online (Sandbox Code Playgroud) 我从库中获得了这些普通的C函数:
struct SAlloc;
SAlloc *new_salloc();
void free_salloc(SAlloc *s);
Run Code Online (Sandbox Code Playgroud)
有什么方法可以用C++将它包装成智能指针(std :: unique_ptr),或者RAII包装器吗?
我主要是对标准库的可能性感到好奇而没有创建我自己的包装器/类.
#include < stdio.h >
#include < conio.h >
#include < stdlib.h >
#include < process.h >
#include < string.h >
#include < math.h >
int count = 0;
typedef struct bitmap24 {
unsigned char header[54];
unsigned char * pixels;
}BMP;
void readBMP(char * filename) {
int i;
FILE * f = fopen(filename, "rb");
FILE * f1 = fopen("save.bmp", "wb");
FILE * pixelVals = fopen("vals.dat", "w");
unsigned char bmppad[3] = {
0,
0,
0
};
if (!f) {
printf("Could not read …
Run Code Online (Sandbox Code Playgroud)