mmap

mmap with /dev/zero

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Say I allocate a big memory (40MB) with mmap using /dev/zero as follows. fd = open("/dev/zero", O_RDWR); a = mmap (0, 4096e4, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FILE, fd, 0); What I understand is that the kernel will initialize memories to zero as the pages are brought into the physical memory (I suppose the modern Linux kernels use Demand paging ). So for example, when the first page is touched and therefore brought into the physical memory, kernel will initialize all of its 4096 bytes to zero, then when the second page is touched,

Why mmap() is faster than sequential IO? [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Possible Duplicate: mmap() vs. reading blocks I heard (read it on the internet somewhere) that mmap() is faster than sequential IO. Is this correct? If yes then why it is faster? mmap() is not reading sequentially. mmap() has to fetch from the disk itself same as read() does The mapped area is not sequential - so no DMA (?). So mmap() should actually be slower than read() from a file? Which of my assumptions above are wrong? 回答1: I heard (read it on the internet somewhere) that mmap() is faster than sequential IO. Is this correct?

Cython file write

匿名 (未验证) 提交于 2019-12-03 01:41:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a sample '.pyx' file Here, certain mmap operation has been done (via C mmap) and the and 'data_len' has been returned I want to read from the offset start upto the data_len area, AND dump it to a random file I am doing this by the following: BUT, getting Syntax error while doing 'write' operation cdef void * startmmaparea def do_dump () offset = < char *> startmmaparea ... with open ( 'abc.bin' , 'wb' ) as fdes : fdes . write ( offset . read ( data_len )) ... expected to write the mmap content to the file. but getting Syntax

Executing Byte Array in Go

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to execute shellcode within a Go program, similar to how you can do it with other languages. Example 1 - Shellcode in C program Example 2 - http://www.debasish.in/2012/04/execute-shellcode-using-python.html All methods have broadly similar techniques - assign the shellcode to executable memory via the OS specific allocation (mmap, virtualalloc, etc) and then execute the code by creating a function pointer pointing to that location before executing. Here is my horrible hacky example at performing the same thing in Go. The

mmap of /dev/mem fails with invalid argument for virt_to_phys address, but address is page aligned

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: For some reason my mmap failed with an Invalid argument message even though my offset is page aligned. Page size is 4096 bytes. Also CONFIG_STRICT_DEVMEM is disabled, i.e. I can access memory above 1MB. Here is my code: void * mmap64 ; off_t offset = 0x000000d9fcc000 ; int memFd = open ( "/dev/mem" , O_RDWR ); if (- 1 == memFd ) perror ( "Error " ); mmap64 = mmap ( 0 , getpagesize (), PROT_WRITE | PROT_READ , MAP_SHARED , memFd , offset ); if ( MAP_FAILED == mmap64 ) { perror ( "Error " ); return - 1 ; } Can someone explain why

Will malloc implementations return free-ed memory back to the system?

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a long-living application with frequent memory allocation-deallocation. Will any malloc implementation return freed memory back to the system? What is, in this respect, the behavior of: ptmalloc 1, 2 (glibc default) or 3 dlmalloc tcmalloc (google threaded malloc) solaris 10-11 default malloc and mtmalloc FreeBSD 8 default malloc (jemalloc) Hoard malloc? Update If I have an application whose memory consumption can be very different in daytime and nighttime (e.g.), can I force any of malloc's to return freed memory to the system?

Redis 基础

匿名 (未验证) 提交于 2019-12-03 00:44:02
基本类型 String,hash,list,set,sorted set(zset) 安装 按照README的安装步骤进行 架构原理 redis单进程,单线程,并发很多的请求,如何变得很快的呢?? 当我们使用多个redis-cli进行连接的时候,我们首先对通过redis-cli连接到了linux kernel,linux kernel自带一个epoll的调用,我们在使用redis服务端去调用linux的系统内核,调用epoll。 啥是epoll? 早期的bio时期 。内核有一个跃迁,变化的过程,socket中的fd可以是nonblock的。如果有1000fd,代表用户进程轮询用1000次kernel的成本问题。于是内核更新新的调用,叫做select,实现多路复用的NIO。之后又进行了一次迭代更新,我们kernel更新mmap,我们系统开放了一个虚拟的共享空间,可以供用户调用。 mmap? 在mmap的共享空间,我们使用红黑树+链表(共享空间并非零拷贝,零拷贝是sendfile),mmap还在kafka中有实际运用 2.使用help进行查询(自带补齐功能) help @string可以查询 3.使用type查看类型 type K 4.set是string类型的,所以使用set的全部为string 5.incr和decr可以加减int的编码类型 i 来源:博客园 作者:

android studio listview长按删除

匿名 (未验证) 提交于 2019-12-03 00:34:01
activity_main.xml 的代码 <? xml version = " 1.0 " encoding = " utf-8 " ?> <android.support.constraint.ConstraintLayout xmlns:android = " http://schemas.android.com/apk/res/android " xmlns:app = " http://schemas.android.com/apk/res-auto " xmlns:tools = " http://schemas.android.com/tools " android:layout_width = " wrap_content " android:layout_height = " match_parent " tools:context = " .MainActivity " > < TextView android:id = " @+id/textView5 " android:layout_width = " 45dp " android:layout_height = " 17dp " android:layout_marginLeft = " 4dp " android:layout_marginStart = " 4dp " android:layout

(void*)mmap()

匿名 (未验证) 提交于 2019-12-03 00:32:02
映射函数mmap 的定义是void* 型 void* mmap(void* start,size_t length,int prot,int flags,int fd,off_t offset); 但是大多数调用时候,要求其是有返回值的。例如定义一个unsigned char *buf 再将buf 作为mmap 函数的返回值。 若直接 使用buf = mmap(void* start,size_t length,int prot,int flags,int fd,off_t offset);则会报错 然后可以讲空指针性强转: unsigned char *buf = ( unsigned char *)mmap( 0 ,creq.size,PROT_READ | PROT_WRITE, MAP_SHARED,newLease,mreq.offset); 在mmap函数前也加上 ( unsigned char *)则可编译通过 转载请标明出处: (void*)mmap() 文章来源: (void*)mmap()

流媒体:V4L2视频获取

匿名 (未验证) 提交于 2019-12-03 00:30:01
从深圳回来已经20多天了,除了完善毕业设计程序和论文,其他时间都去玩游戏了。真的是最后的一段时间能够无忧无虑在校园里挥霍自己的青春了。今天完成的答辩,比想象的要简单,一直以来想把我现在的这个流媒体的东西用文字记录下来,但是都去玩了。但是今天开始还是把这些东西都记录下来。其实整个项目最开始接触的是socket编程,用socket写一个很简单的机遇POP3协议的邮件发送程序都觉得沾沾自喜。现在看来但是确实还是很幼稚的。。。   其实V4L2就是LINUX下的一套API,我刚刚开始接触的时候觉得好难,完全就TMD看不懂啊。。。反正就是各种不靠谱,其实现在看来这些东西不难,其实很简单。只是当时没有决心去做而已。其实大多数的初学者都有我这样的想法,看着这些不熟悉的东西都会很烦躁,沉不住气不想去看。但是事实是多看看多GOOGLE查查基本就能理解了。下面是API的代码解析: 1)打开一个视频设备: fd = open( " /dev/video0 " , O_RDWR /* |O_NONBLOCK */ , 0 );   要从摄像头中回去到图像首先当然要打开一个摄像头,在LINUX中对摄像头的操作是对相应的设备文件进行操作实现的。在LINUX的根文件系统中/dev目录有很多设备文件,其中摄像头对应的是viode0,使用open函数打开,O_RDWR表示读写,O_NONBLOCK表示非阻塞