小编clo*_*Fan的帖子

SynchronizationContext有什么作用?

在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;在方法中,有什么区别?

.net c# multithreading

116
推荐指数
6
解决办法
4万
查看次数

sizeof()如何用于char*(指针变量)?

我有一个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是怎么来的,谢谢!

c

14
推荐指数
4
解决办法
7万
查看次数

在C#中使用BinaryReader解析MNIST数据集我做错了什么?

:我是从分析数据集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)

c# binary endianness mnist

3
推荐指数
1
解决办法
1478
查看次数

为什么稀疏矩阵(0.5)与密集向量相乘比正常乘法慢?

我生成了一个稀疏度为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)

令我困惑的是,由于只有一半的非零数字,我认为稀疏乘法应该更快.

matlab

2
推荐指数
1
解决办法
2625
查看次数

如何知道一个非常小的文件的大小?

假设我有一个非常简单的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)

我认为这是系统为这个文件分配的块数,我如何使用命令来查找这么小的文件的大小?

shell

2
推荐指数
1
解决办法
79
查看次数

如何cp所有不以abc开头的东西?

请不要给我一个利用grep或ls或sed等其他命令的解决方案.

我想知道cp用正则表达式是否可以做到这一点.

bash

2
推荐指数
1
解决办法
76
查看次数

标签 统计

c# ×2

.net ×1

bash ×1

binary ×1

c ×1

endianness ×1

matlab ×1

mnist ×1

multithreading ×1

shell ×1