精华内容
下载资源
问答
  • Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE

    This is not really a research proposal about specific area of functional programming, but a short essay to show my understanding of functional programming, Haskell, and some preliminary thinking.

     

    The understanding of functional programming

    Functional programming is considered as a no assignment statements, no side effects, and referentially transparent programming paradigm. [1] Its special characters and advantages distinguish itself from other programming paradigms, such as imperative programming languages like C.

     

    In reality, modular top-to-bottom design can not only reduce the difficulty of programming and testing, but also improve efficiency by re-use modules. The most powerful tools in functional programming should be higher-order function and lazy evaluation, which can improve program modularization greatly. [1] Higher-order function provides the tool of high degree abstraction, which could combine existed small modules to build a complex larger module. The lazy programming style helps to improve the separation of the definition and the use of computations.

     

    The understanding of Haskell

    Haskell is widely known as a purely functional programming language, which obeys almost all principles of functional programming paradigm but for side effects in IO monad. Moreover, it is a very high level language that really close to human thinking. Although lots of programmers think that their knowledge of lower level languages are what make them very different from normal computer user, it is hardly to deny the power and efficiency of abstract thinking, which could be achieved much easier in humanlike higher level languages, such as Haskell.

     

    Haskell, as a functional programming language, is more mathematic traceable than other languages in different programming paradigms. In another word, it is more suitable to represent mathematical models. This advantage could easily be seen in the abstract syntax representation in Haskell, which is simpler and clearer than representations in other languages, such as JAVA. From this point, Haskell naturally is an efficiently creator of domain-specific embedded languages. Moreover, considering its mathematical nature, Haskell could also be a great tool for some other applications, such as image processing.

     

    Why Haskell is not that popular

    There is no doubt that Haskell is such a powerful programming language with unique characters. However, it is also true that Haskell is not as widely known and used as some other languages, such as C or JAVA. In my opinion, the reason for this might be complicated.

     

    There was a quite interesting question pop up in the class of programming language technology. Considering Haskell as a very high level language, which should be very close to human languages, why is it so difficult to manage compare to other programming languages? The answer from the lecturer was that it takes time to learn, just like human languages. That is very true; at least I cannot see anything special when I start with Haskell. In the opposite, some features, such as the strict type checker, were really annoyed and made me felt tied. It takes time to see the beauty of Haskell and consume even more time to get control of them.

     

    Moreover, compare with other popular programming languages, such as Java, the platform of Haskell is not that strong, which means programmer might need to do lots of work all by themselves. The good thing of this is that each time they can pick and combine very small size modules to achieve their purpose with more independence and less redundancy. In the other side, this also means lots of programmers might be doing similar work in different projects, which is another form of repetition.

     

    What could we do for improvement

    There are at least two things that I think might be helpful for the development of Haskell.

     

    One thing is that platform should be continuing completed. More libraries might be help for reducing the difficulty of programming, especially for people who are not experts. In additional, a friendly relationship between different components might be appreciated. For example, I am having a problem with using ghci and wxHaskell together at the moment. Last but not least, a more comfortable UI might be very helpful to attract people to use. This could be very easily ignored by programmers because they already get used to the existed interface and it does not really matter for them. However, generally speaking, the more people contribute their efforts in the language, the faster it grows. I truly believe a better UI could help people to keep developing their knowledge about this language until they can see its beauty inside.

     

    Another part that might be optimized is the compiler. In recursive program, even a tiny ineffective part exists, might reduce the whole program efficiency dramatically. This amplification forces programmers spent more time on code optimization. However, their optimization is heavily depended on their knowledge and experiences, which is not always reliable. In the same time, similar work is also done by compilers. In a normal compiler, there is a code optimizer between the intermediated code generator and the code generator, which makes compilers very different from each other. It takes intermediated representation as input and sends them out after optimized follow their special algorithms. [2] For instance, the worker/ wrapper transformation is used in compiler optimization. [3] Considering the optimization work done by compilers generally has better design and test in advance, it should have a very stable performance in a certain level. Therefore, the more work done by compiler automatically, the less that programmers need to worry about.

     

    There are other problems still leaved open. As I have mentioned above, higher-order function and lazy evaluation are the most powerful tools in functional programming, which is also true for Haskell. However, everything is a double-edged sword. For example, one “side effect” could be caused by lazy evaluation is running out of memory. As far as I know, no compilers or interpreters could pop up warning messages for this kind of situations in advance and programmers need to always keep an eye on their code. There might be some solutions for this kind of problem, which could be very useful in the improvement of user experiences and program performances.

     

    References:

    [1] John Hughes, Why Functional Programming Matters

    [2] Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman, Compilers Principles, Techniques, & Tool s, Second Edition, Chapter 1, Chapter 4

    [3] Andy Gill and Graham Hutton, The worker/wrapper transformation

     

    展开全文
  • 这些天学习《UNIX环境高级编程》,里面提及到一种空洞文件,即文件中间有大量空洞,'\0'的字符填充。 生成的代码如下 #include <fcntl.h> #include <apue.h> int main() { int fd; if((fd ...

    这些天学习《UNIX环境高级编程》,里面提及到一种空洞文件,即文件中间有大量空洞,'\0'的字符填充。

    生成的代码如下

    #include <fcntl.h>
    #include <apue.h>
    
    int main()
    {
        int fd;
        if((fd = creat("file.hole",FILE_MODE))<0)
          printf("Wrong!");
    
        write(fd,"file hole\n",9);
        lseek(fd,1234,SEEK_SET);
        write(fd,"hello,world\n",11);
    
        exit(0);
    }

     

    然后问题来了。

    Q:编写一个类似CP命令的程序,它复制包含空洞的文件,但不将字节0写到输出文件去。

    A:思路比较简单,就是打开文件以后,一个字符一个字符的读,如果是'\0'就跳过,否则就拷贝到新文件中。好久没有进行文件I/O的操作了,所以有点生疏,用了半个多小时才完成,ubuntu下gcc编译通过。

    /*
     * =====================================================================================
     *
     *       Filename:  reader.c
     *
     *    Description:  copy file but leave the hole alone.
     *
     *        Version:  1.0
     *        Created:  Tuesday, May 01, 2012 02:43:11 CST
     *       Revision:  none
     *       Compiler:  gcc
     *
     *         Author:  Peter Shih (), shihty5@163.com
     *        Company:  UESTC
     *
     * =====================================================================================
     */
    
    #include <stdio.h>
    #include <unistd.h>
    #include <fcntl.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
        FILE * in_fd;
        FILE * out_fd;
        int ch;
        
        if(argc != 3)
        {
            printf("usage: %s source destination \n", *argv);
            exit(1);
        }
        
        if((in_fd = fopen(argv[1],"r"))==NULL)
        {
            perror(argv[1]);
            exit(1);
        }
        
        if((out_fd = fopen(argv[2],"wt"))==NULL)
        {
            perror(argv[2]);
            exit(1);
        }
    
        ch = fgetc(in_fd);
        while(ch!=EOF)
        {
            if(ch!='\0') 
              fputc(ch,out_fd);
            ch = fgetc(in_fd);
        }
    
        fclose(in_fd);
        fclose(out_fd);
    }

    转载于:https://www.cnblogs.com/shihty/archive/2012/05/01/2477920.html

    展开全文
  • 原文:复制一个空洞文件且忽略掉其空洞内容 首先说一下什么叫做空洞文件!比如说,下面这段代码: 1 #include&lt;stdio.h&gt; 2 #include&lt;string.h&gt; 3 #include&lt;stdlib.h&...
    原文:复制一个空洞文件且忽略掉其空洞内容

      首先说一下什么叫做空洞文件!比如说,下面这段代码:

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h>
     4 #include<errno.h>
     5 #include<sys/types.h>
     6 #include<sys/stat.h>
     7 #include<fcntl.h>
     8 #include<unistd.h>
     9 
    10 #define MODE O_CREAT|O_RDWR|O_TRUNC
    11 int main(int argc,char *argv[])
    12 {
    13     int fd;
    14 
    15     if(argc != 2)
    16     {
    17     printf("Usage:%s <filename>\n",argv[0]);
    18     exit(EXIT_FAILURE);
    19     }
    20     if(-1 == (fd=open(argv[1],MODE,0644)))
    21     {
    22     printf("%s[open]%s\n",argv[0],strerror(errno));
    23     exit(EXIT_FAILURE);
    24     }
    25     if(-1 == write(fd,"abcde",5))
    26     {
    27     printf("%s[write]%s\n",argv[0],strerror(errno));
    28     exit(EXIT_FAILURE);
    29     }
    30     if(-1 == lseek(fd,5,SEEK_END))
    31     {
    32     printf("%s[lseek]%s\n",argv[0],strerror(errno));
    33     exit(EXIT_FAILURE);
    34     }
    35     if(-1 == write(fd,"ABCDE",5))
    36     {
    37     printf("%s[write]%s\n",argv[0],strerror(errno));
    38     exit(EXIT_FAILURE);
    39     }
    40     if(-1 == close(fd))
    41     {
    42     printf("%s[close]%s\n",argv[0],strerror(errno));
    43     exit(EXIT_FAILURE);
    44     }
    45     printf("空洞文件已经创建成功!\n");
    46     return 0;
    47 }

     在这段代码中,我首先在文件中写入abcde五个字节的内容,然后在把文件指针从文件尾端向后移动5个字节,再写入ABCDE5个字节的内容!这样在这个文件中,两次abcde中间就会产生一个5个字节空洞,这个空洞的内容都被写成了0。文件的空洞并不要求在磁盘上占用存储区,具体的处理方式和文件系统的实现有关!我这个文件如果用vim打开的话会是这样的效果!

    中间蓝色的^@就表示内容为0的空洞!

      接下来,我们再来谈一谈如何来复制一个空洞文件,并且让忽略掉它的空洞部分的内容!这里我们就利用了空洞内容为0的这个特性!具体的实现方法就是通过查看读出来的文件内容的值是否为0,如果是则忽略,否则就存储起来!具体的实现代码如下:

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<errno.h>
    #include<sys/types.h>
    #include<sys/stat.h>
    #include<fcntl.h>
    #include<unistd.h>
    #define MODE O_RDWR
    #define SIZE 4096
    int main(int argc,char *argv[])
    {
        if(argc != 3)
        {
        printf("Usage: %s source_file destination_file\n",argv[0]);
        exit(EXIT_FAILURE);
        }
    
        int fd_s,fd_d;
        //分别用来存储读出和写入的文件内容
        char buf_r[SIZE],buf_w[SIZE];
        //写入缓存指针的计数器
        int w_l;    //read_length,write_length
        //读出和写入的长度
        int r_len,w_len;
    
        if(-1 == (fd_s=open(argv[1],MODE)))
        {
          printf("%s[open]%s\n",argv[1],strerror(errno));
          exit(EXIT_FAILURE);
        }
        if(-1 == (fd_d=open(argv[2],MODE|O_CREAT|O_TRUNC,0644)))    //如果目标文件已经存在,则将其截短成0
        {
          printf("%s[open]%s\n",argv[2],strerror(errno));
          exit(EXIT_FAILURE);
        }
        //如果文件的内容过于庞大,我这里是分批存储的!且在《Unix环境高级编程》的3.9节已经论证过当SIZE为4096的时候I/O的效率最佳!
        while((r_len=read(fd_s,buf_r,SIZE)) > 0)
        {
          w_l=0;
          //将读出内容中的非空洞内容赋值到buf_w中
          for(int i=0;i<r_len;i++)
          {
              if(buf_r[i] != 0)
              buf_w[w_l++]=buf_r[i];
          }
          //这里得到的w_l表示的是字符数组的长度,注意数组是从0开始的
          if(-1 == (w_len=write(fd_d,buf_w,w_l)))
          {
              printf("%s[write]%s\n",argv[0]+2,strerror(errno));
              exit(EXIT_FAILURE);
          }
        }
        if(-1 == close(fd_s))
        {
          printf("%s[close]%s\n",argv[1]+2,strerror(errno));
          exit(EXIT_FAILURE);
        }
        if(-1 == close(fd_d))
        {
          printf("%s[close]%s\n",argv[2]+2,strerror(errno));
          exit(EXIT_FAILURE);
        }
    
        return 0;
    }

      上面那个程序的思路就是每次读取4096字节,分批读取源文件的内容到buf_r中,然后检查buf_r的内容,如果是0则忽略,否则就暂存到buf_w中,然后将其写入到目标文件中!

    检验这个程序的运行结果我用了一个较大的空洞文件,具体的运行结果如下图:

      

    展开全文
  • 空洞文件1

    千次阅读 2011-07-20 16:21:05
    ls -l file 查看文件逻辑大小du -c file 查看文件实际占用的存储块多少od -c file 查看文件存储的内容空洞文件是个啥玩意?就是有空洞的文件,在日常的常识中,我们使用的文件存放在硬盘分区上的时候,有多大的内容就...

    ls -l file  查看文件逻辑大小

    du -c file     查看文件实际占用的存储块多少

    od -c file  查看文件存储的内容


    空洞文件是个啥玩意?就是有空洞的文件,在日常的常识中,我们使用的文件存放在硬盘分区上的时候,有多大的内容就会占用多大的空间,比如这个文本文件里面写有1000个asc字符,那么就会占用磁盘上1000B的存储空间,为了便于管理文件,文件系统都是按块大小来分配给文件的,假如这个文件系统一个块是4096的话,那么这个文件就会占用一个块的,无论实际的内容是1B还是4000B.如果我们有一个4MB的文件,那么它会在分区中占用:4MB/4096B=1000个块.

    现在我们先做一个实际的无空洞文件来看看:

    #dd if=/dev/urandom of=testfile1 bs=4096 count=1000

    这个命令会从/dev/urandom文件复制1000个块,每块大小4096,到testfile1文件去.

    好了,我们已经有了testfile1这么一个4M的文件了,里面填充了一些随机的内容,你可以more一下.

    然后用ls -l查看这个文件的大小是4096000,用du -h testfile1来查看的话,文件占用的磁盘大小是4M,两者是一样的.

    下来是我们的重点,空洞文件,假如我们有一个文件,它有4M的大小,但是它里边很大一部分都是没有存放数据的,这样可不可以呢?试一下:

    #dd if=/dev/urandom of=testfile2 bs=4096 seek=999 count=1

    这个命令跟前一个命令相似,不同的是,它其实复制了1个块的内容,前面的999个块都跳过了.

    我们ls -l一下,发现文件的大小还是4096000,用du -h testfile2查看,占用的块大小是4K

    我们发现,虽然文件是4M,但是实际在磁盘上只占用了4K的大小,这就是空洞文件的神奇之处.

    实际中的空洞文件会在哪里用到呢?常见的场景有两个:

    一是在下载电影的时候,发现刚开始下载,文件的大小就已经到几百M了.

    二是在创建虚拟机的磁盘镜像的时候,你创建了一个100G的磁盘镜像,但是其实装起来系统之后,开始也不过只占用了3,4G的磁盘空间,如果一开始把100G都分配出去的话,无疑是很大的浪费.

    然后讲一下底层的实现吧,其实这个功能关键得文件系统支持,貌似FAT就不可以吧,linux下一直都很好的支持这一特性,我们举个最简单的ext的例子吧,ext中记录文件实际内容的对应信息的东东是一个叫索引表的东西,里面有十几个条目,每个条目存放对应文件内容块的块号,这样就可以顺序找到对应的文件内容了,大家可能说,几M的一个文件,十几个项哪够啊,不必担心,一般索引表前面几个项目是直接指向文件内容的,如果这几个不够的话,往后的第一个项目不会指向文件内容块,而会指向一个存放项目的块,这样一下多出N个项目来,如果这样还不够,下面的那个是存放指向指向的项目,不好意思,我也绕晕了,总之,前面的是直接指向,下面这个是二级指向,再下面的是二级指向,以此类推,这样,文件系统就可以处理T数量级别的文件,看下图:


    到了空洞文件这里呢,我们只需要把指向没有文件内容部分的索引项目置NULL就好了,这样就不会指向实际的数据块了,也不会占用磁盘空间了,就这么easy~

    至于btrfs这些新一代文件系统呢,在空洞文件这里的原理跟ext还是类似的.

    最后介绍一下linux对空洞文件的处理,经过我最近的一些测试所得:

    在同一文件系统ext4下,cat一个空洞文件到新文件,新文件不再是空洞文件,cp一个空洞文件到新文件,新文件仍然是空洞文件.

    在btrfs跟ext4之间做的结果同上面是一致的,但是在不同文件系统之间cp,因为不同文件系统分配的最小单元不同,所以du结果会不同.

    在nfs的客户端下,在nfs目录下去cp,新文件仍然是空洞文件!!!但是cp会逐个的去比较文件的内容,所以,受网络状况搞得影响,过程有时候会很慢.



    展开全文
  • 产生的空洞的一种方式是,新创建一个文件,先lseek到一个后面的位置,然后写入内容,那么前面的文件部分就是空洞空洞不占用实际的磁盘空间。但是在文件大小的时候,这些空洞仍然被算入。 在复制文件的过程中...
  • 空洞卷积

    2019-03-26 09:31:00
    ... 一、含义 ...空洞卷积是在标准的卷积核里注入空洞,以此来增加感受野/接受域。相比原来的正常卷积运算,空洞卷积 多了一个 超参数称之为 dilation rate 指的是kernel的间隔数量(e.g. 正常的 con...
  • 学习笔记:linux之文件空洞

    千次阅读 2015-03-02 14:33:01
    空洞文件就是有空洞的文件,在日常的常识中,我们使用的文件存放在硬盘分区上的时候,有多大的内容就会占用多大的空间,比如这个文本文件里面写有1000个asc字符,那么就会占用磁盘上1000B的存储空间,为了便于管理文件,
  • 空洞地建议避免空洞

    2007-01-11 11:43:58
    今天,上司给我E-MAIL了一份资料审核意见:要注意一些服务工作内容空洞性,形式性。[@more@] ...
  • 文件空洞空洞文件 lseek()系统调用可以改变文件的偏移量,但如果程序调用使得文件偏移量跨越了文件结尾,然后在执行I/O操作,将会发生什么情况?read()调用会返回0,表示文件结尾。write()调用可以在文件尾...
  • 空洞文件代码

    2016-01-16 12:02:06
    linux练习文件指针移动及内容填写,使用linux系统调用
  • 吃透空洞卷积

    2021-04-13 00:53:53
    点击上方“小白学视觉”,选择加"星标"或“置顶”重磅干货,第一时间送达 本文转自:视学算法一、空洞卷积的提出空洞卷积中文名也叫膨胀卷积或者扩张卷积,英文名也叫Atrous...
  • 曾经炒得火热的Web2.0,现在似乎正逐渐演变成一个越来越空洞的概念,尤其在遭受金融风暴的席卷,这种趋势非常明显。有数据预测,到2011年,Web2.0概念就将被彻底淡忘。使用率将大幅下降 Web2.0概念曾经风靡一时,但...
  • 给位版友,我有这样一个想法,就是创建一个窗口,其背景色为部分透明,也就是说窗口上有一个空洞,能够看到窗口后面的内容,同时,我想讲这个洞后面的内容,放大后投影到另外一个窗口,有点像window自带的那个放大镜...
  • 浅析空洞文件

    千次阅读 2014-08-03 22:08:12
    1.什么是空洞文件? “在UNIX文件操作中,文件位移量可以大于文件的当前长度,在这种情况下,对该文件的下一次写将延长该文件,并在文件中构成一个空洞,这一点是允许的。位于文件中但没有写过的字节都被设为 0。”...
  • 文件空洞引发的思考:空洞与cp

    千次阅读 2010-01-18 18:32:00
    上次课上学了lseek这个函数,可以制造出“空洞”文件。演示中,我们发现,用vi或者od命令查看带空洞的文件,空洞部分填满了字符0。于是产生了: 问题一:空洞文件和用字符0写同样长度的文件一样吗? 我们来写一个...
  • 什么是空洞卷积?

    2021-05-26 19:22:08
    从目的出发 我们在进行特征提取,也就是所谓的下采样的过程当中,可能会损失分辨率,使得原有的特征消失,所以我们想要让得到的图片和原有...可以看到所谓的空洞卷积就是在卷积的计算过程中,有隔过去的内容。我个人对
  • 1.空洞卷积 注要内容如下: 空洞卷积理解 但是呢,对于这篇博客的部分内容我不赞同。 3x3的kernel设置dialted-rate=2时,理应变为"5x5"的kernel,多出来的空洞用0填充,这也是变相的增加了感受野。也就是说,设置...
  • /**  * @file 1.c  * @brief tow process to copy file in one time  * @author HarkHuang  * @date 2014年3月20日  * @version Initial Draft  * @par Copyright (C), 2013-2023, Join ... * @par History
  • 然后看完之后我们才可以进行下面的内容,我们截取其中重要的图进行说明: 4. 计算空洞卷积感受野  空洞卷积就是在传统的卷积中加入了一个dilation rate这个系数。可以从两个方面理解这个参数,从原...
  • arcgis处理空洞shapefile数据

    千次阅读 2018-08-10 18:08:16
    我们有时候会遇到这样的shapefile数据,如下中间会出现数据空洞,即一个大的面数据中含有空洞的情况。具体数据是怎么弄来的,没有去深究,有可能是从tif影像数据转来的。那么现在要做的是,怎么将空洞部分的数据填充...
  • 这里有一份详细指南 然后看完之后我们才可以进行下面的内容,我们截取其中重要的图进行说明: 4. 计算空洞卷积感受野 空洞卷积就是在传统的卷积中加入了一个dilation rate这个系数。可以从两个方面理解这个参数,从...
  • 空洞文件的感想

    千次阅读 2011-07-20 21:43:09
    问题源于写一个类似与cp的程序,复制一个具有空洞的文件,但不将字节0写导输出文件中去(APUE 第4章6题)。我们知道空洞是不占用磁盘空间的,且linux系统自己有cat,cp命令可以复制文件,但是对空洞的处理方式不同:...
  • 空洞卷积的一些理解

    2019-11-21 11:00:22
    看了一些博主的博客发现部分内容有误,部分博主误将 中的i+1认为是dilated rate,其实在初创作者的论文 《M ULTI -S CALE C ONTEXT A GGREGATION BY D ILATED C ONVOLUTIONS》中,并没有将F的下标与dilated rate联系...
  • 地下空洞的探测是工程勘察和煤矿安全生产的一项重要内容。在已知地质条件的基础上,采用了不同排列方式和极距,研究了高密度电法在探测浅部地下水泥管的有效性。研究结果表明,高密度电法能够很好地反映地下空洞的存在,...
  • 内容索引:VB源码,界面编程,椭圆,透明窗体,空洞 带椭圆空洞的透明窗体,VB源代码,窗口的中间有一个椭圆形的洞,完全透明,可看到下边的内容,想知道实现方法的朋友,下载了解一下。
  •     图像分类任务采用的连续的Pooling和Subsampling层整合多尺度的内容信息,降低图像分辨率,以得到全局的预测输出。     在FCN中通过Pooling层增大感受野、缩小图像尺寸,然后通过Upsampling层来还原...
  • 清除日志文件不产生文件空洞

    千次阅读 2020-02-10 14:33:57
    文件空洞:文件内容的大小小于文件磁盘占用的空间 产生原因:如java使用nohup java -jar xxx.jar > log.txt方式启动java程序,但随着日志内容的增多,服务器磁盘空间不足,需要清理日志文件,所以可采用命令echo '' ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 15,760
精华内容 6,304
关键字:

内容空洞