小编Cir*_*四事件的帖子

TLB刷新和页面全局位

在Intel页表结构中,有"页面全局"位表示页表条目是全局使用的.根据我的理解,在覆盖CR3引起的TLB刷新期间,这个全局条目不会被刷新.我的问题是,我们可以假设全局PTE条目一旦设置就永远不会从TLB刷新吗?

paging x86 tlb

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

D:如何创建一个新的空二进制堆来存储整数?

我对如何正确使用Binary Heap提供的内容感到有点困惑std.container.更具体地说,我想创建一个最大的整数堆,所以我尝试写

auto maxHeap = BinaryHeap!int();

并得到一个关于int不能用[]切片的编译器投诉.我试图在Phobos上阅读它的文档,但我不明白如何创建一个新的,空的二进制堆,旨在存储整数.

有人可以借给我一个手吗?

containers d binary-heap

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

创建NDK项目时," - >"的错误基本操作数具有非指针类型"JNIEnv {aka _JNIEnv}"

我创建了我的第一个NDK项目,在屏幕上显示一些文本.我在java中的类NativeLib中使用本机方法,并在C中的类中实现.但我收到错误基本操作数' - >'具有非指针类型'JNIEnv {aka _JNIEnv}

 #include <jni.h>
 #include <string.h>
 #include <stdio.h>
 #include <android/log.h>

#define DEBUG_TAG "MY_NDK_DEMO"
JNIEXPORT jstring JNICALL Java_com_example_helloworld_NativeLib_helloWorld
  (JNIEnv * env, jobject obj) {
    return (*env)->NewStringUTF("Hello World JNI!");
}
Run Code Online (Sandbox Code Playgroud)

android native-code android-ndk

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

为什么二进制堆的实现比Python的stdlib慢?

我一直在实现自己的堆模块,以帮助我理解堆数据结构.我理解它们是如何工作和管理的,但我的实现比标准python heapq模块慢得多,同时执行堆排序(对于大小为100,000的列表,heapq需要0.6s而我的代码需要2s(原来是2.6s,切断它)通过从percDown中取出len()语句并传递长度来减少到2s所以每次方法调用自身时都不必计算len.这是我的实现:

def percDown(lst, start, end, node):
    #Moves given node down the heap, starting at index start, until the heap property is
    #satisfied (all children must be larger than their parent)
    iChild = 2 * start + 1
    i = start
    # if the node has reached the end of the heap (i.e. no children left),
    # return its index (we are done)
    if iChild > end - 1:
        return start
    #if the second child exists and is smaller than …
Run Code Online (Sandbox Code Playgroud)

python binary-heap heapsort

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

如何在GNU GAS中使用字符文字替换数字?

例如,我想写一些类似的东西,'a'而不是0x61像我在C语言中那样。

该手册在以下位置提到了它们:https : //sourceware.org/binutils/docs/as/Chars.html,但如果没有示例,我不确定我是否理解。

assembly gnu-assembler

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

是否可以在VHDL或Verilog中进行交互式用户输入和输出模拟?

例如,我想为没有FPGA 的互动游戏运行模拟:https://github.com/fabioperez/space-invaders-vhdl,这样:

  • 信号由键盘键设置
  • 输出可以显示在窗口上

http://www.nand2tetris.org/这样做,但它使用简化的自定义教育语言.

VHDL的textioread(input,并write(output得到有点接近,但并不完全:

  • read(input 等待换行符,我们想要一些可以检测到的是键盘键是否被按下
  • write(output:需要一些方法来刷新数据,以确保将模拟显示器的渲染器获取它
  • 我们需要一些方法来限制模拟速度

当然,我不需要在VHDL中做任何事情:我只需要一种与VHDL同步与其他程序进行通信的最小方式,然后我就可以在C中用SDL进行显示.

也请访问:https://github.com/tgingold/ghdl/issues/92

严肃的应用:在硬件CPU仿真之上运行交互式Linux内核+ BusyBox,例如https://github.com/lowRISC/lowrisc-chip(使用verilator)该项目目前只与功能模拟器进行交互式仿真(读取ISA)汇编并模拟它的高级功能),并且只进行非交互式Verilog硬件单元测试.

verilog vhdl riscv

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

如何下载 Torvalds Linux Kernel master、(重新)编译它并使用 QEMU 启动它?

几天来,我正在研究一个小项目,以探索内核编程。然而,我在网上看了很多关于内核编译的问题,并在之前问过一个问题,但我在某些时候仍然感到迷茫。

如果我需要进行一些内核编程,我认为使用 Linus Torvalds 的 Linux 源代码将是最好的起点。所以我做了以下操作(来自 MacOS High Sierra)

  • 下载内核源代码:https://github.com/torvalds/linux
  • 解压它
  • 启动终端并运行:
    • vagrant init
    • vagrant up
    • vagrant ssh
  • 连接后,我输入:
    • cd /vagrant/linux 为了进入Linux源解压文件夹
    • make menuconfig 我只是按了确定/保存
    • sudo make -j 4 && sudo make modules_install -j 4 && sudo make install -j 4

现在,我遇到了一个小错误:

agrant @vagrant-ubuntu-trusty-64:/vagrant/Kernel-Programming/linx-kernel$ sudo make -j 4 && sudo make modules_install -j 4 && sudo make install -j 4
  CHK include/config/kernel.release
CHK     include/generated/uapi/linux/version.h
CHK     include/generated/utsrelease.h
CHK     scripts/mod/devicetable-offsets.h
CHK     include/generated/timeconst.h
CHK     include/generated/bounds.h
CHK     include/generated/asm-offsets.h
CALL    scripts/checksyscalls.sh …
Run Code Online (Sandbox Code Playgroud)

linux qemu linux-kernel macos-high-sierra

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

使用glibc在Windows中对sleep()的未定义引用

我制作了一段简单的代码来记录用户输入的内容:

#include <stdio.h>
#include <unistd.h>

int main() {
  char letter;
  printf("Enter in a character:");
  scanf("%c", &letter);
  sleep(2);
  printf("Letter was: %c", letter);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

在这段代码中,它应该在第8行睡2秒.

不幸的是,即使我有正确的,sleep也是一个未定义的引用.

有没有办法在Windows Vista中解决此问题?

c windows sleep

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

如何在没有长度限制的情况下在c ++中获取格式化的std :: string

在c ++中执行此操作的最佳方法是什么(简言之,使用标准库并且易于理解):

std::string s = magic_command("%4.2f", 123.456f)
Run Code Online (Sandbox Code Playgroud)
  • 没有长度限制(char s [1000] = ...)
  • 其中"%4.2f"是任何c格式的字符串(例如,它将被赋予printf)

我知道为纯c建议的snprintf malloc组合

将未知长度的格式化数据写入字符串(C编程)

但使用c ++有没有更好,更简洁的方法呢?

我也知道建议的std :: ostringstream方法

在C++中将float转换为std :: string

但我想传递ac格式字符串,如"%4.2f",我找不到用ostringstream这样做的方法.

c++ string string-formatting

0
推荐指数
3
解决办法
906
查看次数

Vim 如何从函数中设置视觉模式选择?

我有我想要的选择的开始和结束(行/列)对。

如何将其设置为实际的视觉选择?

前任:

我有缓冲区:

 1 2
 3 4
 5 6
Run Code Online (Sandbox Code Playgroud)

开始:2,1

结束:3,2

:cal SetSelection()
Run Code Online (Sandbox Code Playgroud)

通话后所需的视觉选择:

3 4
5 6
Run Code Online (Sandbox Code Playgroud)

“SetSelection()”是什么样的?

编辑

迄今为止最好的解决方案,根据答案进行错误检查

"put user in visual mode and set the visual selection

"if arguments are not valid, nothing is changed, and raises an exception

":param 1:

    "Visual mode to leave user in.

    "must be either one of:

    "- 'v' for visual (default)
    "- "\<s-v>" for line visual
    "- "\<c-v>" for block visual
":type 1: string

":returns: 0

":raises: bad mode …
Run Code Online (Sandbox Code Playgroud)

vim

0
推荐指数
1
解决办法
1268
查看次数

如何在C++中添加两个数组?

我需要将两个数组一起添加.为什么以下如何工作?

#include <iostream>
using namespace std;
int main ()
 {   
        int sumvals[3];
        int nums[3];

        sumvals [0] = 1;
        sumvals [1] = 2;
        sumvals [2] = 3;


        for (i=0; i <= 3; i++)
        {
          sumvals[i] = sumvals[i] + numbs [i];
          cout << "the sum of the array elements is: " << sumvals << endl;

         }
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
2
解决办法
3万
查看次数