小编Bla*_*tar的帖子

Linux proc模块中的虚拟地址到物理地址转换

我正在尝试在Linux上创建自己的proc节点"os_pagemap"(使用odroid)

该节点的目标是打印所有物理内存页面的信息.(sudo cat/proc/os_pagemap)

像这样 :

[PHY] Virt 483252 Phy 266908 VMA 0 PID 5773 PNAME com.sec.android.app.keyboard
[PHY] Virt 483253 Phy 266909 VMA 0 PID 5773 PNAME com.sec.android.app.keyboard
[PHY] Virt 483254 Phy 266910 VMA 0 PID 5773 PNAME com.sec.android.app.keyboard
[PHY] Virt 398391 Phy 266920 VMA /dev/ashmem/dalvik-bitmap-1 PID 5773 PNAME com.sec.android.app.keyboard
Run Code Online (Sandbox Code Playgroud)

其中VMA是指VMA名称

为了实现目标,我的设计是这样的:

1. read_lock(&tasklock)
2. for_each_process(p) => get pids
3. read_unlock(&tasklock)
4. Loop for each pid
   1)task = get_pid_task(pid)
   2)if task==NULL => skip
   3)mm=task->mm
   4)down_read(&mm->mmap_sem)
   5)Loop for each vma in mm …
Run Code Online (Sandbox Code Playgroud)

c memory-management kernel-module linux-kernel

5
推荐指数
0
解决办法
656
查看次数

动态编程可以与递归一起使用吗?

我理解为什么DP比简单的递归更有效.

但是,我知道DP是使用memoization技术的递归.

对于Fibonacci,像这样:

int DP[10000]; //initalized by 0

int f(int num){
    if (DP[num] != 0)
        return DP[num];

    DP[num] = f(num -1) + f(num - 2);
    return DP[num];
}
Run Code Online (Sandbox Code Playgroud)

我总是以这种递归方式使用DP,并且它在ACM等算法问题上运行良好.

最近,我知道大多数人都不会以这种方式使用DP.

他们像这样使用DP:

int fib(int n)
{
  /* Declare an array to store Fibonacci numbers. */
  int f[n+1];
  int i;

  /* 0th and 1st number of the series are 0 and 1*/
  f[0] = 0;
  f[1] = 1;

  for (i = 2; i <= n; i++)
  {
      /* Add the previous 2 …
Run Code Online (Sandbox Code Playgroud)

algorithm recursion dynamic-programming

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

重新访问A *算法:是否必须检查打开列表或关闭列表?

我正在研究A *算法,并且对重新访问有些困惑。

当我的教授解释A *时,他说如果我重新访问一个已经在封闭列表中的节点,

我必须检查重新访问的费用与原始费用。

如果重新访问便宜,我应该在封闭列表中放弃一个节点,然后在其上添加重新访问的节点。

所以伪代码是这样的:

GeneralGraphSearch( v )
Prepare two empty lists: OPEN, CLOSED
Insert v with Coste(v) into OPEN
While forever
    If OPEN is empty, return failure
    while forever
       v = the node with the lowest cost in OPEN
       remove v from OPEN
       if v is not in CLOSED // v is not visited
        break 
       else if the new cost is cheaper than the cost of v in CLOSED
        remove v in CLOSED
        break
       end if
    end …
Run Code Online (Sandbox Code Playgroud)

algorithm a-star

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