memory-mapping

Memory mapped collections in Java

回眸只為那壹抹淺笑 提交于 2020-01-05 04:43:05
问题 I'm filling up the JVM Heap Space. Changing parameters to give more heap space to the JVM, or changing something in my algorithm in the code not to use so much space are two of the most recommended options. But, if those two have already been tried and applied, and I still get out of memory exceptions, I'd like to see what the other options are. I found out about this example of "Using a memory mapped file for a huge matrix" and a library called HugeCollections which are an interesting way to

How to memory map (mmap) a linux block device (e.g. /dev/sdb) in Java?

爷,独闯天下 提交于 2020-01-01 09:36:09
问题 I can read/write a linux block device with Java using java.nio . The following code works: Path fp = FileSystems.getDefault().getPath("/dev", "sdb"); FileChannel fc = null; try { fc = FileChannel.open(fp, EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE)); } catch (Exception e) { System.out.println("Error opening file: " + e.getMessage()); } ByteBuffer buf = ByteBuffer.allocate(50); try { if(fc != null) fc.write(buf); } catch (Exception e) { System.out.println("Error writing to

WC vs WB memory? Other types of memory on x86_64?

假如想象 提交于 2019-12-30 11:32:41
问题 Could you describe the meanings and the differences between WC and WB memory on x86_64? For completeness, please, describe other types of memory on x86_64, if any. 回答1: I will first start with Writeback caching (WB) since it is easier to understand. Writeback caching As the name implies this caching strategy tries to delay the writes to the system memory as long as possible. The idea is to use only the cache, ideally. However, since the cache has a finite size smaller than the finite size of

WC vs WB memory? Other types of memory on x86_64?

不问归期 提交于 2019-12-30 11:31:51
问题 Could you describe the meanings and the differences between WC and WB memory on x86_64? For completeness, please, describe other types of memory on x86_64, if any. 回答1: I will first start with Writeback caching (WB) since it is easier to understand. Writeback caching As the name implies this caching strategy tries to delay the writes to the system memory as long as possible. The idea is to use only the cache, ideally. However, since the cache has a finite size smaller than the finite size of

Mapping multiple data arrays to arbitrary fixed memory addresses

浪子不回头ぞ 提交于 2019-12-25 14:25:09
问题 I'm working on a program on a 64-bit Linux machine that needs to map multiple data arrays, of arbitrary length, to fixed memory addresses over which I have no control. I thought mmap() with MAP_FIXED and MAP_ANONYMOUS was the way to go, for example: mmap((void *) 0x401000, 0x18e, PROT_NONE, MAP_ANONYMOUS | MAP_FIXED, -1, 0); However, every time I call this function, it returns MAP_FAILED. I've set fd to -1, which I know is required by some systems, the address is a multiple of my page size

Is there any limitation for using MapViewOfFile?

两盒软妹~` 提交于 2019-12-24 01:48:12
问题 I am trying to use memory-mapped files as: hFile = ::CreateFile(State.Path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN, 0);//open the file if(hFile !=INVALID_HANDLE_VALUE){ hMap= ::CreateFileMapping(hFile, 0, PAGE_READONLY | SEC_COMMIT, 0, 0, 0);//create Mem mapping for the file in virtual memory if( hMap!=NULL){ base = ::MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);//load the mapped file into the RAM //start to compare some bytes (values) from

Convert a pointer to an array in C++

▼魔方 西西 提交于 2019-12-22 17:36:10
问题 The CreateFileMapping function returns a pointer to a memory mapped file, and I want to treat that memory mapping as an array. Here's what I basically want to do: char Array[] = (char*) CreateFileMapping(...); Except apparently I can't simply wave my arms and declare that a pointer is now an array. Do you guys have any idea how I can do this? I don't want to copy the the values the pointer is pointing to into the array because that will use too much memory with large files. Thanks a bunch,

What real platforms map hardware ports to memory addresses?

岁酱吖の 提交于 2019-12-20 10:08:53
问题 I sometimes see statements that on some platforms the following C or C++ code: int* ptr; *ptr = 0; can result in writing to a hardware input-output port if ptr happens to store the address to which that port is mapped. Usually they are called "embedded platforms". What are real examples of such platforms? 回答1: Most systems in my experience use memory-mapped I/O. The x86 platform has a separate, non-memory-mapped I/O address space (that uses the in / out family of processor op-codes), but the

Why data and stack segments are executable?

给你一囗甜甜゛ 提交于 2019-12-19 05:10:40
问题 I have just noticed that my simple program has its data and stack segments executable. I saw it in /proc/[pid]/maps, and simple code confirmed it. For example: ; prog.asm section .data code: db 0xCC ;int3 section .text global _start _start: jmp code mov rax, 60 ; sys_exit mov rdi, 0 syscall then nasm -f elf64 prog.asm ld -o prog prog.o ./prog causes prog to execute int3 instruction. Programs written in C and built with gcc have their data, stack and heap non-executable, so why those written

munmap() failure with ENOMEM with private anonymous mapping

喜夏-厌秋 提交于 2019-12-18 03:51:13
问题 I have recently discovered that Linux does not guarantee that memory allocated with mmap can be freed with munmap if this leads to situation when number of VMA (Virtual Memory Area) structures exceed vm.max_map_count . Manpage states this (almost) clearly: ENOMEM The process's maximum number of mappings would have been exceeded. This error can also occur for munmap(), when unmapping a region in the middle of an existing mapping, since this results in two smaller mappings on either side of the