tall_man has asked for the wisdom of the Perl Monks concerning the following question:

I need random access to several large binary files, and I was trying to use PDL::IO::FlexRaw. However, doing a second mapflex seems to clobber the pdl of the first one. The same thing does not happen in an equivalent C program. I am running perl 5.8.0 on Linux 2.4.18.

Does anyone have an idea what could be going wrong, and if there is a work-around? Thanks.

Here is the code:

use strict; use warnings; use PDL; use PDL::IO::FlexRaw; # Places in the file with known values. my @specials = (1314724, 1388624, 7737986, 7813911); my @nexts_expected = (1354770, 6315154, 6315155, 1354771); sub testMap { my $pdl = shift; for (my $i = 0; $i < @specials; $i++) { my $nxt = $pdl->at($specials[$i]); if ($nxt != $nexts_expected[$i]) { print "Unexpectedly got $nxt at $i instead of ",$nexts_expect +ed[$i],"\n"; } else { print "As expected $nxt at $i is ",$nexts_expected[$i],"\n"; } } } # if # Example xxx.hdr: # Long # 1 # 9129591 my $pdl1 = mapflex("xxx"); print "Test values before second mapflex:\n"; testMap($pdl1); my $pdl2 = mapflex("yyy"); print "Test values after second mapflex:\n"; testMap($pdl1); print "Did the contents of the second mmap overwrite?\n"; testMap($pdl2); __END__ Output: Test values before second mapflex: As expected 1354770 at 0 is 1354770 As expected 6315154 at 1 is 6315154 As expected 6315155 at 2 is 6315155 As expected 1354771 at 3 is 1354771 Test values after second mapflex: Unexpectedly got 5735779 at 0 instead of 1354770 Unexpectedly got 5340568 at 1 instead of 6315154 Unexpectedly got 4725878 at 2 instead of 6315155 Unexpectedly got 3013470 at 3 instead of 1354771 Did the contents of the second mmap overwrite? Unexpectedly got 5735779 at 0 instead of 1354770 Unexpectedly got 5340568 at 1 instead of 6315154 Unexpectedly got 4725878 at 2 instead of 6315155 Unexpectedly got 3013470 at 3 instead of 1354771 Warning: special data without datasv is not freed currently!!. Warning: special data without datasv is not freed currently!!.
Here is a snippet of the C code that works:
fd = open(argv[1], O_RDONLY); if (fd < 0) { perror(argv[1]); exit(1); } mapstart = (long *)mmap((void *)0, len, PROT_READ, MAP_PRIVATE, fd, offset & ~MAP_MASK); if ((long)mapstart < 0) { perror("mapstart failed"); exit(1); } close(fd); printf("Test values before second mmap:\n"); testMap(mapstart); fd2 = open(argv[2], O_RDONLY); if (fd < 0) { perror(argv[2]); exit(1); } mapstart2 = (long *)mmap((void *)0, len, PROT_READ, MAP_PRIVATE, fd2 +, offset & ~MAP_MASK); if ((long)mapstart2 < 0) { perror("mapstart2 failed"); exit(1); } close(fd2); printf("Test values before second mmap:\n"); testMap(mapstart); printf("Did the contents of the second mmap overwrite?\n"); testMap(mapstart2);

Replies are listed 'Best First'.
Re: PDL mapflex clobbers previous?
by etj (Priest) on Jun 06, 2022 at 01:56 UTC
Re: PDL mapflex clobbers previous?
by D.M. (Initiate) on Jul 22, 2008 at 08:01 UTC
    Did you get a solution ? After years of PDL abstinence I stumbled across the same problem w/ Linux 2.6.nn Any help welcome, D.M.