mmap

Sp效率分析和理解

帅比萌擦擦* 提交于 2019-11-29 00:26:29
目录介绍 01.Sp简单介绍 1.1 Sp作用分析 1.2 案例分析思考 02.Sp初始化操作 2.1 如何获取sp 2.2 SharedPreferencesImpl构造 03.edit方法源码 04.put和get方法源码 4.1 put方法源码 4.2 get方法源码 05.commit和apply 5.1 commit源码 5.2 apply源码 06.总结分析 好消息 博客笔记大汇总【16年3月到至今】,包括Java基础及深入知识点,Android技术博客,Python学习笔记等等,还包括平时开发中遇到的bug汇总,当然也在工作之余收集了大量的面试题,长期更新维护并且修正,持续完善……开源的文件是markdown格式的!同时也开源了生活博客,从12年起,积累共计N篇[近100万字,陆续搬到网上],转载请注明出处,谢谢! 链接地址: https://github.com/yangchong211/YCBlogs 如果觉得好,可以star一下,谢谢!当然也欢迎提出建议,万事起于忽微,量变引起质变! 01.Sp简单介绍说明 1.1 Sp作用分析 sp作用说明 SharedPreferences是Android中比较常用的存储方法,它可以用来存储一些比较小的键值对集合,并最终会在手机的/data/data/package_name/shared_prefs/目录下生成一个 xml

Redis

那年仲夏 提交于 2019-11-28 23:34:23
基本类型 String,hash,list,set,sorted set(zset) 安装 按照README的安装步骤进行 架构原理 redis单进程,单线程,并发很多的请求,如何变得很快的呢?? 当我们使用多个redis-cli进行连接的时候,我们首先对通过redis-cli连接到了linux kernel,linux kernel自带一个epoll的调用,我们在使用redis服务端去调用linux的系统内核,调用epoll。 啥是epoll? 在linux kernel中,我们使用client,可以使用socket直接连接kernel。早期,我们可以使用read fd <unistd.h>读取文件描述符,线程/进程使用 read fd去读取linux kernel(因为这时候socket这个时期是阻塞的(blocking)),整个计算机,并没有实时处理打来的线程,这是 早期的bio时期 。内核有一个跃迁,变化的过程,socket中的fd可以是nonblock的。如果有1000fd,代表用户进程轮询用1000次kernel的成本问题。于是内核更新新的调用,叫做select,实现多路复用的NIO。之后又进行了一次迭代更新,我们kernel更新mmap,我们系统开放了一个虚拟的共享空间,可以供用户调用。 mmap? 在mmap的共享空间,我们使用红黑树+链表(共享空间并非零拷贝

How to mmap the stack for the clone() system call on linux?

北慕城南 提交于 2019-11-28 21:39:35
The clone() system call on Linux takes a parameter pointing to the stack for the new created thread to use. The obvious way to do this is to simply malloc some space and pass that, but then you have to be sure you've malloc'd as much stack space as that thread will ever use (hard to predict). I remembered that when using pthreads I didn't have to do this, so I was curious what it did instead. I came across this site which explains, "The best solution, used by the Linux pthreads implementation, is to use mmap to allocate memory, with flags specifying a region of memory which is allocated as it

Python - Download File Using Requests, Directly to Memory

六眼飞鱼酱① 提交于 2019-11-28 21:33:34
The goal is to download a file from the internet, and create from it a file object, or a file like object without ever having it touch the hard drive. This is just for my knowledge, wanting to know if its possible or practical, particularly because I would like to see if I can circumvent having to code a file deletion line. This is how I would normally download something from the web, and map it to memory: import requests import mmap u = requests.get("http://www.pythonchallenge.com/pc/def/channel.zip") with open("channel.zip", "wb") as f: # I want to eliminate this, as this writes to disk f

How would one prevent MMAP from caching values?

此生再无相见时 提交于 2019-11-28 19:15:42
问题 I've written a linux driver that ioremaps exports PCI BAR0 for a particular device to a sysfs binary attribute allowing userspace to directly control it. The problem rears when I attempt to MMAP on top of the attribute to directly access that bit of memory (from a userland program). Reads succeed just fine and return expected values, though when I write to that memory it appears to be cached somewhere between the kernel and memory and not delivered to the GMCH root complex (and therefore the

Examining mmaped addresses using GDB

风流意气都作罢 提交于 2019-11-28 18:53:08
I'm using the driver I posted at Direct Memory Access in Linux to mmap some physical ram into a userspace address. However, I can't use GDB to look at any of the address; i.e., x 0x12345678 (where 0x12345678 is the return value of mmap) fails with an error "Cannot access memory at address 0x12345678". Is there any way to tell GDB that this memory can be viewed? Alternatively, is there something different I can do in the mmap (either the call or the implementation of foo_mmap there) that will allow it to access this memory? Note that I'm not asking about /dev/mem (as in the first snippet there)

mmap problem, allocates huge amounts of memory

瘦欲@ 提交于 2019-11-28 17:52:40
问题 I got some huge files I need to parse, and people have been recommending mmap because this should avoid having to allocate the entire file in-memory. But looking at 'top' it does look like I'm opening the entire file into the memory, so I think I must be doing something wrong. 'top shows >2.1 gig' This is a code snippet that shows what I'm doing. Thanks #include <stdio.h> #include <stdlib.h> #include <err.h> #include <fcntl.h> #include <sysexits.h> #include <unistd.h> #include <sys/stat.h>

appending to a memory-mapped file

a 夏天 提交于 2019-11-28 17:32:48
问题 I'm constantly appending to a file of stock quotes (ints, longs, doubles, etc.). I have this file mapped into memory with mmap. What's the most efficient way to make newly appended data available as part of the memory mapping? I understand that I can open the file again (new file descriptor) and then mmap it to get the new data but that seems to be inefficient. Another approach that has been suggested to me is to pre-allocate the file in 1mb chunks, write to a specific position until reaching

How to share APC cache between several PHP processes when running under FastCGI?

点点圈 提交于 2019-11-28 16:53:47
I'm currently running several copies of PHP/FastCGI, with APC enabled (under Apache+mod_fastcgi, if that matters). Can I share cache between the processes? How can I check if it's shared already? (I think the apc.mmap_file_mask ini setting might be involved, but I don't know how to use it.) (One of the reasons I think its not shared at the moment is that the apc.mmap_file_mask , as reported by the apc.php web interface flips between about 3 different values as I reload.) APC does not currently share its cache between multiple php-cgi workers running under fastcgi or fcgid. See this feature

Shared Memory or mmap - Linux C/C++ IPC

纵饮孤独 提交于 2019-11-28 16:52:27
问题 The context is Inter-Process-Communication where one process("Server") has to send fixed-size structs to many listening processes("Clients") running on the same machine. I am very comfortable doing this in Socket Programming. To make the communication between the Server and the Clients faster and to reduce the number of copies, I want to try out using Shared Memory(shm) or mmaps. The OS is RHEL 64bit. Since I am a newbie, please suggest which should I use. I'd appreciate it if someone could