memory-mapping

Memory-mapped files in Java

痴心易碎 提交于 2019-11-29 02:16:13
I've been trying to write some very fast Java code that has to do a lot of I/O. I'm using a memory mapped file that returns a ByteBuffer: public static ByteBuffer byteBufferForFile(String fname){ FileChannel vectorChannel; ByteBuffer vector; try { vectorChannel = new FileInputStream(fname).getChannel(); } catch (FileNotFoundException e1) { e1.printStackTrace(); return null; } try { vector = vectorChannel.map(MapMode.READ_ONLY,0,vectorChannel.size()); } catch (IOException e) { e.printStackTrace(); return null; } return vector; } The problem that I'm having is that the ByteBuffer .array() method

How does copy_from_user from the Linux kernel work internally?

巧了我就是萌 提交于 2019-11-27 22:56:32
How exactly does the copy_from_user() function work internally? Does it use any buffers or is there any memory mapping done, considering the fact that kernel does have the privilege to access the user memory space? The implementation of copy_from_user() is highly dependent on the architecture. On x86 and x86-64, it simply does a direct read from the userspace address and write to the kernelspace address, while temporarily disabling SMAP (Supervisor Mode Access Prevention) if it is configured. The tricky part of it is that the copy_from_user() code is placed into a special region so that the

Memory-mapped files in Java

断了今生、忘了曾经 提交于 2019-11-27 21:52:08
问题 I've been trying to write some very fast Java code that has to do a lot of I/O. I'm using a memory mapped file that returns a ByteBuffer: public static ByteBuffer byteBufferForFile(String fname){ FileChannel vectorChannel; ByteBuffer vector; try { vectorChannel = new FileInputStream(fname).getChannel(); } catch (FileNotFoundException e1) { e1.printStackTrace(); return null; } try { vector = vectorChannel.map(MapMode.READ_ONLY,0,vectorChannel.size()); } catch (IOException e) { e

Binary search in a sorted (memory-mapped ?) file in Java

只愿长相守 提交于 2019-11-27 19:07:38
问题 I am struggling to port a Perl program to Java, and learning Java as I go. A central component of the original program is a Perl module that does string prefix lookups in a +500 GB sorted text file using binary search (essentially, "seek" to a byte offset in the middle of the file, backtrack to nearest newline, compare line prefix with the search string, "seek" to half/double that byte offset, repeat until found...) I have experimented with several database solutions but found that nothing

Retrieving the memory map of its own process in OS X 10.5/10.6

倾然丶 夕夏残阳落幕 提交于 2019-11-27 13:21:04
In Linux, the easiest way to look at a process' memory map is looking at /proc/PID/maps , giving something like this: 08048000-08056000 r-xp 00000000 03:0c 64593 /usr/sbin/gpm 08056000-08058000 rw-p 0000d000 03:0c 64593 /usr/sbin/gpm 08058000-0805b000 rwxp 00000000 00:00 0 40000000-40013000 r-xp 00000000 03:0c 4165 /lib/ld-2.2.4.so 40013000-40015000 rw-p 00012000 03:0c 4165 /lib/ld-2.2.4.so 4001f000-40135000 r-xp 00000000 03:0c 45494 /lib/libc-2.2.4.so 40135000-4013e000 rw-p 00115000 03:0c 45494 /lib/libc-2.2.4.so 4013e000-40142000 rw-p 00000000 00:00 0 bffff000-c0000000 rwxp 00000000 00:00 0

Binary search in a sorted (memory-mapped ?) file in Java

落花浮王杯 提交于 2019-11-27 10:28:17
I am struggling to port a Perl program to Java, and learning Java as I go. A central component of the original program is a Perl module that does string prefix lookups in a +500 GB sorted text file using binary search (essentially, "seek" to a byte offset in the middle of the file, backtrack to nearest newline, compare line prefix with the search string, "seek" to half/double that byte offset, repeat until found...) I have experimented with several database solutions but found that nothing beats this in sheer lookup speed with data sets of this size. Do you know of any existing Java library

How does copy_from_user from the Linux kernel work internally?

霸气de小男生 提交于 2019-11-26 21:13:56
问题 How exactly does the copy_from_user() function work internally? Does it use any buffers or is there any memory mapping done, considering the fact that kernel does have the privilege to access the user memory space? 回答1: The implementation of copy_from_user() is highly dependent on the architecture. On x86 and x86-64, it simply does a direct read from the userspace address and write to the kernelspace address, while temporarily disabling SMAP (Supervisor Mode Access Prevention) if it is

Retrieving the memory map of its own process in OS X 10.5/10.6

流过昼夜 提交于 2019-11-26 16:18:25
问题 In Linux, the easiest way to look at a process' memory map is looking at /proc/PID/maps , giving something like this: 08048000-08056000 r-xp 00000000 03:0c 64593 /usr/sbin/gpm 08056000-08058000 rw-p 0000d000 03:0c 64593 /usr/sbin/gpm 08058000-0805b000 rwxp 00000000 00:00 0 40000000-40013000 r-xp 00000000 03:0c 4165 /lib/ld-2.2.4.so 40013000-40015000 rw-p 00012000 03:0c 4165 /lib/ld-2.2.4.so 4001f000-40135000 r-xp 00000000 03:0c 45494 /lib/libc-2.2.4.so 40135000-4013e000 rw-p 00115000 03:0c

How to access physical addresses from user space in Linux?

馋奶兔 提交于 2019-11-26 03:56:19
问题 On a ARM based system running Linux, I have a device that\'s memory mapped to a physical address. From a user space program where all addresses are virtual, how can I read content from this address? 回答1: You can map a device file to a user process memory using mmap(2) system call. Usually, device files are mappings of physical memory to the file system. Otherwise, you have to write a kernel module which creates such a file or provides a way to map the needed memory to a user process. Another