[Win32utils-devel] Need some help with latest win32-mmap

Daniel Berger djberg96 at gmail.com
Wed Oct 11 23:18:36 EDT 2006


On 10/11/06, Heesob Park <phasis at gmail.com> wrote:
>
> Hi,
>
> 2006/10/12, Berger, Daniel <Daniel.Berger at qwest.com>:
> >
> > > -----Original Message-----
> > > From: win32utils-devel-bounces at rubyforge.org
> > > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of
> > > Johan Nilsson
> > > Sent: Wednesday, October 11, 2006 1:13 AM
> > > To: Development and ideas for win32utils projects
> > > Subject: Re: [Win32utils-devel] Need some help with latest win32-mmap
> >
> > <snip>
> >
> > > I haven't tried this myself, and judging from the MSDN docs it's also
> > > not entirely clear that it will work, but: Try using zero(0)
> > > as the size
> > > when calling MapViewOfFile, and then use VirtualQuery to retrieve the
> > > size of the view.
> >
> > I've been tinkering with this a bit.  I think I'm doing something wrong.
> > Here's a private method I created to get the view size.  Note that this
> > requires modifying the "VirtualQuery" (in windows/memory.rb) method
> > signature to "LPL":
> >
> > def get_view_size
> >   mbi = [0,0,0,0,0,0,0].pack('LLLLLLL') # MEMORY_BASIC_INFORMATION
> >   VirtualQuery(@base_address, mbi, mbi.size)
> >   return mbi[12,4].unpack('L').first # RegionSize
> > end
>
>
> should be:
>
> def get_view_size
>   mbi = [0,0,0,0,0,0,0].pack('LLLLLLL') # MEMORY_BASIC_INFORMATION
>   VirtualQuery(@address, mbi, mbi.size)
>   return mbi[12,4].unpack('L').first # RegionSize
> end
>
>
> Then, in MMap.new, I have this:
> >
> > if @open
> >   size = get_view_size()
> >   @address = MapViewOfFileEx(@mh, @access, 0, 0, size, @base_address)
> > else
> >   @address = MapViewOfFileEx(@mh, @access, 0, 0, 0, @base_address)
> > end
>
>
> should be:
>
> if @open
>   @address = MapViewOfFileEx(@mh, @access, 0, 0, 0, @base_address)
>   @size = get_view_size()
> else
>   @address = MapViewOfFileEx(@mh, @access, 0, 0, 0, @base_address)
> end
>
>
> The first issue, I think, is that get_view_size always returns 65536
> > (64k).  I'm guessing 64k is a default amount of memory to allocate or
> > something.  Using the examples I provided previously, I would expect
> > this to be 20.
> >
> > The second issue is that MapViewOfFileEx fails if I try to pass a size.
> > I think I'm misreading the docs.
> >
> > I'd make some more commits so you could just check this out from
> > RubyForge, but I'm getting timeouts at the moment from rubyforge.org...
> >
> > Regards,
> >
> > Dan
>
>
> It seems the memory map in windows aligns 4k boundary.
> When created with 20, get_view_size returns 4096
> When created with 20000, get_view_size returns 20480.
>
> Regards,
>
> Park Heesob
>

Many thanks.  I have checked the changes into CVS, along with the semaphore
locking code.

All, please take a look and let me know if you think I'm missing anything or
if there are any other interface changes you think need to be made.  I
wasn't sure about the method_missing approach, but I think it's nicer than
the old getvar/setvar approach.  I can always add that back in if necessary.

If all looks good, I'll try to get a release out this weekend.

Regards,

Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/win32utils-devel/attachments/20061011/9dddc674/attachment.html 


More information about the win32utils-devel mailing list