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_expected[$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!!. #### 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);