在Programming C#一书中,它有一些示例代码SynchronizationContext:
SynchronizationContext originalContext = SynchronizationContext.Current;
ThreadPool.QueueUserWorkItem(delegate {
string text = File.ReadAllText(@"c:\temp\log.txt");
originalContext.Post(delegate {
myTextBox.Text = text;
}, null);
});
Run Code Online (Sandbox Code Playgroud)
我是线程的初学者,所以请详细回答.首先,我不知道上下文是什么意思,程序保存在originalContext什么?当Post方法被触发时,UI线程会做什么?
如果我问一些愚蠢的事情,请纠正我,谢谢!
编辑:例如,如果我只是写myTextBox.Text = text;在方法中,有什么区别?
我有一个C代码:
char s1[20];
char *s = "fyc";
printf("%d %d\n", sizeof(s1), sizeof(s));
return 0;
Run Code Online (Sandbox Code Playgroud)
它回来了
20 8
Run Code Online (Sandbox Code Playgroud)
我想知道8是怎么来的,谢谢!
:我是从分析数据集MNIST在C#http://yann.lecun.com/exdb/mnist/
我正在尝试Int32从二进制文件中读取第一个:
FileStream fileS = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(fileS);
int magicNumber = reader.ReadInt32();
Run Code Online (Sandbox Code Playgroud)
但是,它给了我一个无意义的数字:50855936.
如果我使用 File.ReadAllBytes()
buffer = File.ReadAllBytes(fileName);
Run Code Online (Sandbox Code Playgroud)
然后查看字节,它工作正常(前四个字节现在代表2049),我做了什么错误的BinaryReader?
文件格式如下(我正在尝试读取第一个幻数):
All the integers in the files are stored in the MSB first (high endian) format used by most non-Intel processors. Users of Intel processors and other low-endian machines must flip the bytes of the header.
Run Code Online (Sandbox Code Playgroud)
TRAINING SET LABEL FILE(train-labels-idx1-ubyte):
[offset] [type] [value] [description]
0000 32 bit integer 0x00000801(2049) magic number (MSB …Run Code Online (Sandbox Code Playgroud) 我生成了一个稀疏度为0.5的矩阵,我想知道它的速度乘以密集向量与正常方式的乘法相比.
function sparseTest()
A = sprand(1000, 1000, 0.5);
test(A);
test(full(A));
end
function test(A)
tic;
b = rand(size(A, 2), 1);
for i = 1:10000
c = A * b;
end
toc;
end
Run Code Online (Sandbox Code Playgroud)
结果是
Elapsed time is 10.968797 seconds.
Elapsed time is 10.194440 seconds.
Run Code Online (Sandbox Code Playgroud)
令我困惑的是,由于只有一半的非零数字,我认为稀疏乘法应该更快.
假设我有一个非常简单的ASCII文件,只包含
11111111
Run Code Online (Sandbox Code Playgroud)
现在,我想使用一个命令来查找它实际拥有的字节数,而不是系统为其分配的字节数.我试过了
ln -s
Run Code Online (Sandbox Code Playgroud)
和
du
Run Code Online (Sandbox Code Playgroud)
但他们只输出
4
Run Code Online (Sandbox Code Playgroud)
我认为这是系统为这个文件分配的块数,我如何使用命令来查找这么小的文件的大小?