研:内存映射方式处理大数据(20G) mmap+memcpy

【Linux】Linux编程之 mmap解析 前言 虚拟内存系统通过将虚拟内存分割为称作虚拟页(Virtual Page,VP)大小固定的块,一般情况下,每个虚拟页的大小默认是4096字节。同样的,物理内存也被分割为物理页(Physical Page,PP),也为4096字节。 一、mmap基本原理和分类 在LINUX中我们可以使用mmap用来在进程虚拟内存地址空间中分配地址空间,创建和物理内存的映射关系。 映射关系可以分为两种 1、文件映射 磁盘文件映射进程的虚拟地址空间,使用文件内容初始化物理内存。 2、匿名映射 初始化全为0的内存空间。 而对于 阅读详情

目的,快速读写20G数据,,

方法:mmap+memcpy

状态:暂时放弃治疗

已搞定: 

bug: mmap+memcpy, char 转int 又出问题了

研:mmap + memcpy 与传统 ofream读写对比

研:mmap 总结

乱到我都不想看,,,毕竟草稿本。

 

各位大佬,
我想用mmap+memcpy将A文件(超过6gb,都是字符) 每个字符变成一个int数据 在写进B文件,但老是core 掉,我的做法如下:
1.mmap好A,关闭文件
2.mmap好B,长度4096,
3.循环读A的1024 个字符,转int,放进一个int 数组,
4.mmcpy 这个数组就B
5.改变offset,再映射,继续2-5的循环

请各位大佬指导下呗,跪谢

 

 

 还有个问题啊,就是我A是6gb,那么我B直接指定大小4*6gb是否刚好?

 

 刚开始应该用truncate()把文件B的长度设置为文件A的长度。应该是你没扩大文件B的长度,mmap()的参数offset超过文件B的长度,mmap()失败。

 

使用mmap和memcpy编写文件复制程序 开始没有区分好匿名内存和文件映射之间的区别,而出现了一些错误。/********************** > File Name: test_cp.c > Created Time: 2018年03月03日 星期六 09时55分29秒 ****************************/ #ifdef USE_MAP_ANON #define _BSD_S... 阅读详情

相关推荐

C++高性能文件系统开发:内存映射I/O原理与虚拟内存交互深度解析

在操作系统和文件系统开发中,内存映射I/O(MMIO)是一种将文件或设备直接映射到进程虚拟地址空间的核心技术。其原理基于虚拟内存管理,通过建立虚拟内存区域(VMA)与文件地址空间的关联,实现按需分页(Demand Paging)机制。当程序首次访问映射区域时,会触发缺页中断(Page Fault),内核随后从页缓存(Page Cache)加载数据或分配物理页,这一过程由内存管理单元(MMU)协同完成。该技术的核心价值在于实现了近乎零拷贝的数据访问,显著减少了用户态与内核态之间的上下文切换和数据复制开销,从而

weixin_34117211的博客 434

Linux内核级PCIe DMA驱动:FPGA零拷贝内存映射实战

PCIe DMA是实现主机与加速器(如FPGA)高效数据交互的核心机制,其本质是通过硬件直连绕过CPU搬运,依赖DMA地址空间映射、缓存一致性管理及MSI中断协同。技术价值在于显著降低延迟、提升吞吐并缓解系统调度压力,广泛应用于AI推理加速、实时图像处理、高速数据采集等对确定性时延敏感的嵌入式Linux场景。本文聚焦裸金属级驱动开发,深入解析基于dma_alloc_coherent的连续内存分配、设备树中BAR与MSI中断的精准声明、环形描述符链初始化,以及mmap零拷贝映射的关键实现细节,为软硬协同工程师

weixin_34268310的博客 1705

Linux下FPGA PCIe DMA驱动开发:零拷贝、MSI中断与mmap直通

PCIe设备驱动是嵌入式Linux与硬件协同的核心技术,其本质是实现CPU与外设间的高效内存共享与事件同步。原理上需完成BAR空间映射、DMA一致性内存分配、MSI中断注册及用户态内存直通等关键环节。技术价值在于突破传统字符设备的拷贝瓶颈,达成纳秒级响应与GB/s级吞吐。典型应用场景包括高速数据采集、实时信号处理与AI加速器互联。本文聚焦FPGA PCIe设备驱动落地实践,深度解析dma_alloc_coherent内存管理、MSI中断配置及mmap零拷贝机制,覆盖4.19~6.5内核适配与跨厂商FPGA兼

weixin_33985679的博客 449

Linux FPGA PCIe DMA驱动实战:解决dma_map_single失败与mmap段错误

PCIe设备DMA通信是嵌入式与加速计算中的核心能力,其本质依赖IOMMU地址翻译、DMA掩码协商与缓存一致性保障。原理上,Linux内核需完成设备使能、BAR映射、DMA域绑定及内存屏障同步等多阶段协同;技术价值在于实现零拷贝、低延迟、高吞吐的FPGA-主机数据通路;典型应用场景包括视频流处理、AI推理卸载和实时信号采集。若跳过pci_enable_device()或遗漏dma_set_mask_and_coherent(),将直接导致dma_map_single()静默返回NULL;而用户态mmap失败

weixin_34152820的博客 443

C语言考试系统实战:文件读写、结构体与内存映射

C语言考试系统是嵌入式与教学场景中典型的工程化实践载体,其核心在于掌握文件读写操作代码、字符串处理、结构体设计及内存管理等基础能力。原理上需理解二进制文件序列化、静态数组与内存映射(mmap)的性能权衡、位运算压缩存储等关键技术,技术价值体现在轻量部署、抗低配环境、防数据丢失与多维成绩分析。典型应用场景包括机房标准化考试、实训项目交付、教务数据对接等,尤其适用于Windows老旧设备与Dev-C++开发环境。本文聚焦真实落地中的题库加载优化、身份防伪机制与CSV导出编码兼容等关键环节,深度融合c语言文件读写

weixin_34279579的博客 338

广告推荐算法 - 学习笔记(持续更新中)

本篇博客,是我用来记录学习广告推荐算法的一些笔记和总结。王喆:"深度"学习计算广告计算广告系统的核心目标是通过数据、算法和技术,在合适的场景下,将最相关的广告精准推送给目标用户,同时实现广告主媒体平台和用户之间的多方利益最大化。广告主:需求方核心目标:通过精准投放广告,最大化转化(如点击、购买)并控制成本,提升投资回报率(ROI)。关键行为:广告创建,定向设置,预算与出价策略,效果监控媒体平台:供给方核心目标:最大化广告收入,同时保持用户体验以避免用户流失。

qq_39748832的博客 2197

GK2302量产工具下载方法,GK2302开卡教程,GK2301LT怎么开卡方法,附GK2302开卡工具,GK2301LT量产软件下载

​每种量产软件的操作流程可能略有不同,因此必须按照要求操作。为确保安全,建议使用量产部落网下载的原版量产开卡软件。

A520091000的博客 2123

详解Unity中的粒子系统Particle System (三)

上一篇我们详细讲解了有关主模块的全部内容,已经对粒子系统的基本运作有了足够的了解,本篇就来讲一下被粒子系统默认启用的Emission、Shape、Renderer模块又在粒子系统中扮演着怎么样的作用吧。

梦小天幼的博客 1万+

stm32使用TB6600驱动器控制42BYGH型步进电机

stm32使用TB6600驱动器控制42BYGH型步进电机

qq_35653974的博客 9587

【复现论文】Looking here or there? Gaze Following in 360-Degree Images

论文:Looking here or there?

RichardoMu的博客 1131

ESD放电模式以及电源箝位 (power clamp )电路

由于ESD电压具有很快的上升速度(其ESD脉冲上升时间约在10ns左右),Vrc端的电压因为RC延迟效应无法跟得上VDD端的ESD电压上升速度,Vrc端的为低电位导致反相器工由于ESD电压具有很快的上升速度(其ESD脉冲上升时间约在10ns左右),Vrc端的电压因为RC延迟效应无法跟得上VDD端的ESD电压上升速度,Vrc端的为低电位导致反相器工作将输出端Vout电压上拉到高电位。从而Vg端的高电位触发导通了NMOS元件(Mesd)的晶体管,因而ESD电流便经由Mesd而泄放掉。由于晶体管Mesd的栅极导通

DOG_BITE_DOG的博客 2万+

三边定位的最小二乘法运用

已知:条件基站到移动台的距离D,基站的坐标(xi,yi,zi) 求:移动台的坐标(x,y,z) 运用最小二乘法的核心是找到最小二乘法的矩阵形式即 Ax=B 在本次实验中通过三边定位计算得到 A=[A;2*(xi-x1),2*(yi-y1),2*(zi-z1]; %系数矩阵A b=[b;D1^2-Di^2+xi^2+yi^2+zi^2-x1^2-y1^2-z1^2]; %增广矩阵b

qq_26250141的博客 1万+

Unity3D 加密 Assembly-CSharp.dll (Android平台) 防止反编译

0、加密的原理 Unity3D 是基于 Mono的,我们平时写的 C# 脚本都被编译到了 Assembly-CSharp.dll ,然后 再由 Mono 来加载、解析、然后执行。 Mono 加载 Assembly-CSharp.dll 的时候就是读取文件到内存中,和平时读取一个 游戏资源 文件没什么区别。 为了防止别人破解,我们会对游戏资源加密,简单点的 比如修改文件的一个字节 或者 位移一下

Circle 8722

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

上一篇: 器:gnome-system-monitor 快捷键
下一篇: 搬: 含有对象成员指针的类的对象成员指针初始化问题
nedwons
博客等级 码龄9年 311粉丝 572原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值