memory-mapped-files

Change the encoding to UTF-8 on a stream (MemoryMappedViewStream)

江枫思渺然 提交于 2019-12-06 03:55:37
I am using the code below to read a ~2.5Gb Xml file as fast as I can (thanks to MemoryMappedFile). However, I am getting the following exception: " '.', hexadecimal value 0x00, is an invalid character. Line 9778, position 73249406. ". I beleive it is due to some encoding problem. How do I make sure that the MemoryMappedViewStream reads the file using UTF-8? static void Main(string[] args) { using (var file = MemoryMappedFile.CreateFromFile(@"d:\temp\temp.xml", FileMode.Open, "MyMemMapFile")) { using (MemoryMappedViewStream stream = file.CreateViewStream()) { Read(stream); } } } static void

c# MemoryMappedFile in .net 3.5

旧时模样 提交于 2019-12-05 20:50:23
I need to use MemoryMappedFile class in .net 3.5... is there any way to find the code of the classes used in .net 4.0 and create to use in .net 3.5? thanks in advance If you need memory mapped files in .NET 3.5, you could also write your own wrapper around the respective Win32 methods from scratch. This might take a bit more effort, but it avoids any licensing issues. .NET 4 uses a whole new CLR, and I wouldn't be at all surprised to find that enough had changed under the hood to make this basically infeasible. Basically, you should be working to use a version of .NET that supports the

Truncate memory mapped file

落爺英雄遲暮 提交于 2019-12-05 14:03:02
问题 I am using memory mapped IO for an index file, but the problem is that I'm not able to resize the file if it is mostly empty. Somewhere before: MappedByteBuffer map = raf.getChannel().map(MapMode.READ_WRITE, 0, 1 << 30); raf.close(); // use map map.force(); map = null; Resize: for (int c = 0; c < 100; c++) { RandomAccessFile raf = new RandomAccessFile(indexFile, "rw"); try { raf.setLength(newLen); if (c > 0) LOG.warn("used " + c + " iterations to close mapped byte buffer"); return; } catch

Opening memory-mapped file with encoding

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 12:55:58
Memory mapped file is an efficient way for using regex or doing manipulation on large binary files. In case I have a large text file (~1GB), is it possible to work with an encoding-aware mapped file? Regex like [\u1234-\u5678] won't work on bytes objects and converting the pattern to unicode will not work either (as "[\u1234-\u5678]".encode("utf-32") for example will not understand the range correctly). Searching might work if I convert the search pattern from str to bytes using .encode() but it's still somewhat limited and there should be a simpler way instead of decoding and encoding all day

Traditional IO vs memory-mapped

北城以北 提交于 2019-12-05 12:40:55
I'm trying to illustrate the difference in performance between traditional IO and memory mapped files in java to students. I found an example somewhere on internet but not everything is clear to me, I don't even think all steps are nececery. I read a lot about it here and there but I'm not convinced about a correct implementation of neither of them. The code I try to understand is: public class FileCopy{ public static void main(String args[]){ if (args.length < 1){ System.out.println(" Wrong usage!"); System.out.println(" Correct usage is : java FileCopy <large file with full path>"); System

Access SQLite db from MMF

☆樱花仙子☆ 提交于 2019-12-05 12:29:42
I'm using System.Data.SQLite lib to access my SQLite database. I want to load the db file to memory and use MMF (Memory Mapped Files) to access the database. Is this possible using the default SQLite library? edit: Alternatives on how I can have an in-memory database are welcome. no... You can: create an in-memory DB instance (specify in connection string Data Source=:memory: ) and load the contents from the DB file into that instance... when you change contents of the in-memory instance your DB file won't get updated... you could later on save the in-memory instance content into a DB file...

Memory Mapped File Length

徘徊边缘 提交于 2019-12-05 09:15:24
I am working on memory mapped files. Is there any way to know the length of memory mapped file content? What I want is to append the existing memory mapped file. Its easy to append the bytes in the file but I am looking to append string. We can check the CAPACITY property, but it returns the bytes size I think. To be more clear, I am explaining the scenario. I am creating Memory mapped file A. I write "Hello" when I create it. It works fine. Now I want to write the "World" into existing file A. I am using below code for this: var file = MemoryMappedFile.OpenExisting("myFile"); string str =

Accessing the number of shared memory mapped file views (Windows)

核能气质少年 提交于 2019-12-05 07:24:46
I am developing a multi-platform C++ application (mainly Windows and Linux), now I face the need to be able to limit the maximum number of instances of the application that may run at the same time (in the same machine). I have already a shared memory module that uses: Linux: System V shared memory (shmget(), shmat()...) Windows: Memory mapped files (CreateFileMapping(), OpenFileMapping(), MapViewOfFile(),...) In linux I can easily control the number of instances running with this kind of code: #include <stdio.h> #include <sys/shm.h> #include <unistd.h> #include <stdlib.h> int main(void) {

How would I design and implement a non-blocking memory mapping module for node.js

余生颓废 提交于 2019-12-05 05:33:33
There exists the mmap module for node.js: https://github.com/bnoordhuis/node-mmap/ As the author Ben Noordhuis notes, accesing mapped memory can block, which is why he does not recommend it anymore and discontinued it. So I wonder how would I design a non-blocking memory mapping module for node.js? Threading, Fibers, ? Obviously this nearby raises the question if threading in node.js would just happen elsewhere instead of the request handler. josh3736 When talking about implementing some native facility in a non-blocking fashion, the first place to look is libuv . It is how node's core modules

Memory Mapped File and Win Service - Cannot find File Created By Server

强颜欢笑 提交于 2019-12-04 22:45:51
I am trying to create a memory mapped file with a windows service so it can hold a lot of static data that other windows applications can use. My issue is that when I start the service - the service can read and write the memory mapped file easily. However, the windows apps cannot. They get a file not found error. Using the same class to read and write the memory mapped file, in two windows applications I have no issues. So, I am under the belief that the use of the memory mapped files is correct but there is something else - probably in the realm of windows services that I am missing. I have