mmap

Substitute for NSData deprecated dataWithContentsOfMappedFile

怎甘沉沦 提交于 2019-12-19 07:52:15
问题 So +(id)dataWithContentsOfMappedFile:(NSString *)path is apparently deprecated since iOS 5.0. It sounds to me like I should avoid using it, but then what should I use instead? I was using mmap to create memory mapped files and it worked with iOS5, but in iOS6, something is wrong because I get an error as soon as I try to update or read the buffer. int fd = open(path, O_RDWR); off_t offset = 0; snapshotData = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset); close(fd); 回答1: Use

Explanation/information sought: Windows write I/O performance with “fsync” (FlushFileBuffers)

拈花ヽ惹草 提交于 2019-12-19 06:19:42
问题 This question is in follow up of an earlier question I posted: Windows fsync (FlushFileBuffers) performance with large files. Where I found a possible solution but also new questions. While benchmarking different scenarios for fsynced writes, I found a number of surprising results. I am hoping someone can help explain or point me in the direction of information that explains these results. What this benchmark does is writing random blocks (pages 4096 bytes large) to a file sequentially in

《Glibc内存管理》笔记DAY2

a 夏天 提交于 2019-12-19 04:22:33
目录 Ptmalloc内存管理设计 Main_arena 与 non_main_arena chunk 的组织 空闲 chunk 容器 sbrk 与 mmap 内存分配概述 内存回收概述 边界标记法 内容来源 Ptmalloc内存管理设计 具有长生命周期的大内存分配使用 mmap。 特别大的内存分配总是使用 mmap。 具有短生命周期的内存分配使用 brk,因为用 mmap 映射匿名页,当发生缺页异常时,linux 内核为缺页分配一个新物理页,并将该物理页清 0,一个 mmap 的内存块需要映射多个物理页,导致多次清 0 操作,很浪费系统资源,所以引入了 mmap分配阈值动态调整机制,保证在必要的情况下才使用 mmap 分配内存。 尽量只缓存临时使用的空闲小内存块,对大内存块或是长生命周期的大内存块在释放时都直接归还给操作系统。 对空闲的小内存块只会在 malloc 和 free 的时候进行合并,free 时空闲内存块可能放入 pool 中,不一定归还给操作系统。 收缩堆的条件是当前 free 的块大小加上前后能合并 chunk 的大小大于 64KB,并且堆顶的大小达到阈值,才有可能收缩堆,把堆最顶端的空闲内存返回给操作系统。 需要保持长期存储的程序不适合用 ptmalloc 来管理内存。 为了支持多线程,多个线程可以从同一个分配区(arena)中分配内存,ptmalloc假设线程

How to get writes via an mmap mapped memory pointer to flush immediately?

天涯浪子 提交于 2019-12-19 03:37:17
问题 I'm having what appears to be a caching problem when using /dev/mem with mmap on a dual ARM processor system (Xilinx Zynq, to be exact). My configuration is asymmettric, with one processor running Linux and the other processor running a bare metal application. They communicate through a block of RAM that isn't in the Linux virtual memory space (it was excluded by the devicetree file). When my userspace Linux application writes to memory using the pointer returned from mmap(), it can take

use mmap in C to write into memory. [closed]

浪子不回头ぞ 提交于 2019-12-18 15:51:33
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I want to use mmap() to create a file containing some integers. I want to write to this file by writing to memory. I know that the data in memory is binary format and hence the data in file will also be in binary. Can I use mmap for this purpose? where can I find good resources on

mmap vs sbrk, performance comparison

我的梦境 提交于 2019-12-18 13:39:20
问题 Which of these calls is faster on average? I've heard that mmap is faster for smaller allocations but I haven't heard a comparison of either. Any information on performance for these would be nice. 回答1: You should tag this with a particular implementation (like linux ) since the answer surely varies by implementation. For now I'll assume Linux since it's the most popular. With that said, brk is in theory more optimizable, and in practice it runs about 10% faster on my machine. Allocating one

get the physical address of a buffer under Linux

大憨熊 提交于 2019-12-18 13:25:07
问题 I am running Linux kernel 3.3 on Xilinx's Microblaze with full MMU. the task that I am doing requires me to know the following: I need to create a text file (buffer) and locate the physical address of this buffer and I don't want the kernel to write this file into discontinuous regions of memory. the reason I need this because I have a DMA engine that streams data from a preset physical memory address, so I need to force Linux to create the buffer file at that exact memory location, so that

Reading a file to string with mmap

佐手、 提交于 2019-12-18 12:38:28
问题 I'm trying to read a file to a string using mmap. I was following this example: http://www.lemoda.net/c/mmap-example/index.html My code looks like this unsigned char *f; int size; int main(int argc, char const *argv[]) { struct stat s; const char * file_name = argv[1]; int fd = open (argv[1], O_RDONLY); /* Get the size of the file. */ int status = fstat (fd, & s); size = s.st_size; f = (char *) mmap (0, size, PROT_READ, 0, fd, 0); for (i = 0; i < size; i++) { char c; c = f[i]; putchar(c); }

Reading a file to string with mmap

流过昼夜 提交于 2019-12-18 12:38:06
问题 I'm trying to read a file to a string using mmap. I was following this example: http://www.lemoda.net/c/mmap-example/index.html My code looks like this unsigned char *f; int size; int main(int argc, char const *argv[]) { struct stat s; const char * file_name = argv[1]; int fd = open (argv[1], O_RDONLY); /* Get the size of the file. */ int status = fstat (fd, & s); size = s.st_size; f = (char *) mmap (0, size, PROT_READ, 0, fd, 0); for (i = 0; i < size; i++) { char c; c = f[i]; putchar(c); }

Analyzing memory mapping of a process with pmap. [stack]

南楼画角 提交于 2019-12-18 09:06:48
问题 I'm trying to understand how stack works in Linux. I read AMD64 ABI sections about stack and process initialization and it is not clear how the stack should be mapped. Here is the relevant quote (3.4.1): Stack State This section describes the machine state that exec (BA_OS) creates for new processes. and It is unspecified whether the data and stack segments are initially mapped with execute permissions or not. Applications which need to execute code on the stack or data segments should take