memory-mapped-files

Java - Heap vs Direct memory access

谁说胖子不能爱 提交于 2019-12-02 16:01:15
I recenty came across sun.misc.Unsafe class, allowing user to allocate,deallocate and in general access memory in a similar fashion like in C. I read in a couple of blogs that tackle this issue e.g. Which is faster - heap or direct memory - test results claim heap Off-heap memory vs DirectByteBuffer vs Heap - Off-heap seems to be fastest Memory mapped files for time series data - MappedByteBuffer faster than heap objects Article 1) seems to be in contradiction with the other ones and I fail to comprehend why. DirectMemoryBuffer is using sun.misc.Unsafe under the hood (so is MappedByteBuffer ),

How to allocate and free aligned memory in C

爷,独闯天下 提交于 2019-12-02 15:37:54
How do you allocate memory that's aligned to a specific boundary in C (e.g., cache line boundary)? I'm looking for malloc/free like implementation that ideally would be as portable as possible --- at least between 32 and 64 bit architectures. Edit to add: In other words, I'm looking for something that would behave like (the now obsolete?) memalign function, which can be freed using free. Jerome Here is a solution, which encapsulates the call to malloc, allocates a bigger buffer for alignment purpose, and stores the original allocated address just before the aligned buffer for a later call to

C++ MapViewOfFile fails

放肆的年华 提交于 2019-12-02 09:01:49
I am trying to memory-map a file on Windows using VS2010. I am doing this in a DLL. The first instance of the DLL maps the file just fine. The second instance within the same process causes *ppvData = ::MapViewOfFile( *phMapping, FILE_MAP_READ, 0, 0, 0 ); to fail with the error "Not enough memory available for this command". I am not sure why this happens. If I map 2 different files instead of twice the same file, all works fine, so I don't trust the "Not enough memory" error message. Thank you. hr = MapFile(sPath, &m_hVoiceData, &m_pVoiceData,wsErr ); HRESULT CTTSEngObj::MapFile( wstring

FILE_FLAG_DELETE_ON_CLOSE and memory mapped files

此生再无相见时 提交于 2019-12-02 04:09:27
Not that it's particularly useful, but I'm curious as to why the following works, is it simply because the page still happens to be in memory even after the file is deleted? In which case, if the page is swapped out the data will be lost? #include <iostream> #include <memory> #include <windows.h> int main() { typedef std::unique_ptr<void, decltype(&CloseHandle)> Handle; typedef std::unique_ptr<void, decltype(&UnmapViewOfFile)> View; View v(nullptr, UnmapViewOfFile); { Handle h(CreateFile( L"test", GENERIC_READ | GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, nullptr ),

Are Windows Memory Mapped File contents always zeroed by default?

我的未来我决定 提交于 2019-12-02 00:56:34
问题 I've determined empirically that, on my system, a memory mapped file created to be a certain size is always completely zeroed by default. For example, using the call HANDLE hMM = CreateFileMapping (h, NULL, PAGE_READWRITE, 0, 0x01400000,//20MB NULL); .. and writing into a mapped view of that file always results in a 20MB file that is completely zeroed, except where I have written non-zero data. I'm wondering if uninitialized parts of the file can be assumed to be zeros. Is this behavior

Are Windows Memory Mapped File contents always zeroed by default?

穿精又带淫゛_ 提交于 2019-12-01 22:24:48
I've determined empirically that, on my system, a memory mapped file created to be a certain size is always completely zeroed by default. For example, using the call HANDLE hMM = CreateFileMapping (h, NULL, PAGE_READWRITE, 0, 0x01400000,//20MB NULL); .. and writing into a mapped view of that file always results in a 20MB file that is completely zeroed, except where I have written non-zero data. I'm wondering if uninitialized parts of the file can be assumed to be zeros. Is this behavior guaranteed on Windows in general? The CreateFileMapping documentation ( Remarks section) explicitly states

Release Memory Mapped Memory

落花浮王杯 提交于 2019-12-01 18:42:29
I am memory mapping a large file (~200GB) into a single region/view and sequentially writing to it. Every now and then I perform a boost::interprocess::mapped_region::flush(last, current, false) . After a while the process uses up the entire system memory. Which, from what I understand, is normal as it will be releasing the memory as other process request memory. This works well on Windows 8. However, running on Windows 7 it doesn't seem to play well with the drivers for AJA video cards and it starts affecting performance (dropping IO packets). Is there any way I can force the Windows 7 to

Memory-Mapped File is Faster on Huge Sequential Read? Why?

隐身守侯 提交于 2019-12-01 17:56:48
I used the code below to measure the performance difference between reading large, sequential reads of a memory-mapped file, as compared to just calling ReadFile : HANDLE hFile = CreateFile(_T("D:\\LARGE_ENOUGH_FILE"), FILE_READ_DATA, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL); __try { const size_t TO_READ = 32 * 1024 * 1024; char sum = 0; #if TEST_READ_FILE DWORD start = GetTickCount(); char* p = (char*)malloc(TO_READ); DWORD nw; ReadFile(hFile, p, TO_READ, &nw, NULL); #else HANDLE hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL)

Opening a Memory Mapped File causes FileNotFoundException when deployed in IIS

浪尽此生 提交于 2019-12-01 16:46:50
Following the code example from this website, I created a windows console application that creates a mapped memory file: using (var file = MemoryMappedFile.CreateNew("myFile", 24)) { var bytes = new byte[24]; for (var i = 0; i < bytes.Length; i++) bytes[i] = (byte)(65 + i); using (var writer = file.CreateViewAccessor(0, bytes.Length)) { writer.WriteArray<byte>(0, bytes, 0, bytes.Length); } Console.WriteLine("Run memory mapped file reader before exit"); Console.WriteLine("Press any key to exit ..."); Console.ReadLine(); } in a new asp.net web application I read the MMF using the code: protected

System Error 0x5: CreateFileMapping()

社会主义新天地 提交于 2019-12-01 16:10:06
I wish to implement IPC using Named Shared Memory. To do this, one of the steps is getting a handle to a Mapping Memory Object , using CreateFileMapping(). I do it exactly as MSDN website reccommends: http://msdn.microsoft.com/en-us/library/aa366551(v=VS.85).aspx : hFileMappingHandle = CreateFileMapping ( INVALID_HANDLE_VALUE, // use paging file NULL, // default security PAGE_READWRITE, // read/write access 0, // maximum object size (high-order DWORD) 256, // maximum object size (low-order DWORD) "Global\\MyFileMappingObject" // name of mapping object ); DWORD dwError = GetLastError(); However