Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory map large files on windows #24

Open
Dmarcoux111 opened this issue Nov 8, 2019 · 4 comments
Open

memory map large files on windows #24

Dmarcoux111 opened this issue Nov 8, 2019 · 4 comments

Comments

@Dmarcoux111
Copy link

@ozra First off, really cool library. Any chance of adding support for mapping large files on windows? From the notes it seemed like that was limited to linux as of now? And I attempted a 3gb and mmap failed. Use case is visualizing large data sets like pointclouds.

@Dmarcoux111
Copy link
Author

Dmarcoux111 commented Nov 10, 2019

@ozra

Update... I tried just mapping the file as 1gb chunks and I run into the same error after gig number 2...
*note, mapping the file works fine with python's numpy.memmap
Codez:

`// const file = path.join( remote.app.getAppPath(), 'pointclouds', 'las', 'test.las' )
const file = path.join( remote.app.getAppPath(), 'test.tif' )
const size = fs.statSync( file ).size
const fd = fs.openSync( file, 'r' )
const pages = []
const bufferSize = 2**30

console.time('test')
for ( let offset = 0; offset < size; offset+=bufferSize ) {
console.log( 'start:', offset )
let pageSize = bufferSize;
if ( pageSize > size ) {
pageSize = size % bufferSize
}
console.log( pageSize )
const protection = window.MMAP.PROT_READ
const privacy = window.MMAP.MAP_PRIVATE
const advise = window.MMAP.MADV_RANDOM
const buffer = window.MMAP.map( pageSize, protection, privacy, fd, offset, advise )
pages.push( buffer )
console.log( 'end:', offset + pageSize )
console.log( '\n\n' )
}
console.timeEnd('test')`

results in:

Uncaught Error: mmap failed, 0

@Dmarcoux111
Copy link
Author

Another update... If I allocate 4 1gb buffers on the same file starting at offset 0, there is also no issue. It seems like maybe the issue is the number being passed into either offset or size?

@Dmarcoux111
Copy link
Author

Dmarcoux111 commented Nov 11, 2019

@ozra So I actually fixed this by changing the type of the input arguments for size and offset to long longs.... idk if this breaks things on other architectures, but posting my answer here for anyone that runs into a similar problem.

`
constexpr void* hinted_address = nullptr; // Just making things uber-clear...

const size_t    size            = static_cast<size_t>(get_v<long long>(info[0]));

const int       protection      = get_v<int>(info[1]);

const int       flags           = get_v<int>(info[2]);

const int       fd              = get_v<int>(info[3]);

const size_t    offset          = static_cast<size_t>(get_v<long long>(info[4], 0));

const int       advise          = get_v<int>(info[5], 0);

`
*disclaimer, I haven't written C plus plus in like 5 years so be cautious

@UmanShahzad
Copy link

We made https://github.com/ipinfo/mmap-utils with a fix for this.

Repository owner deleted a comment from SuryaSg Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants