[HN Gopher] How to Allocate Memory
       ___________________________________________________________________
        
       How to Allocate Memory
        
       Author : tosh
       Score  : 66 points
       Date   : 2026-02-24 18:56 UTC (3 days ago)
        
 (HTM) web link (geocar.sdf1.org)
 (TXT) w3m dump (geocar.sdf1.org)
        
       | anonymousDan wrote:
       | Nice reference, thanks.
        
       | 5o1ecist wrote:
       | > The operating system often has a tool for allocating contiguous
       | virtual memory space called pages.
       | 
       | "often". sheesh. _*rolls eyes_ *
       | 
       | It does not apply for Windows.
       | 
       | You cannot reserve or commit 4k-pages in Windows. For historical
       | reasons, the minimum amount of memory you can reserve/commit is
       | 64k.
       | 
       | This also applies to mapping 4k-pages around, meaning you can't.
       | 
       | 64k is the rather wastefull lower limit.
        
         | dooglius wrote:
         | How does WSL1 do it then?
         | 
         | Anyway, the section you are quoting makes no claim as the the
         | permitted granularity.
        
         | binarycrusader wrote:
         | Can you clarify?
         | 
         | As far as I'm aware, dwAllocationGranularity returned via
         | GetSystemInfo determines the MEM_RESERVE alignment and size.
         | Yes, in practice this is always 64KiB but may not always be
         | true in the future.
         | 
         | Additionally, dwPageSize returned via GetSystemInfo determines
         | the alignment and size for MEM_COMMIT which in practice is 4KiB
         | or 16KiB.
         | 
         | Put differently, while an application might be stuck with
         | allocation-granularity reservations, the actual commit is in
         | units of page size, right?
         | 
         | https://learn.microsoft.com/en-us/windows/win32/memory/reser...
         | 
         | Page protections are also based on page size afaik, for
         | example: https://www.softwareverify.com/blog/leaking-memory-
         | with-virt...
         | 
         | Or the way I read it, you might be stuck with a
         | dwAllocationGranularity reservation, but the actual commit
         | increment is in units of dwPageSize.
        
           | 5o1ecist wrote:
           | Ha! You're right! It applies to reservation and mapping, not
           | to committing!
           | 
           | Thank you, it's been a while!
        
         | Just_Harry wrote:
         | And the historical reason why the allocation-granularity is 64
         | KB instead of 4 KB (or the page-size) is that it made DLL
         | relocation very slightly faster on Alpha AXP processors. No,
         | really!
         | https://devblogs.microsoft.com/oldnewthing/20031008-00/?p=42...
        
       | 011101101 wrote:
       | HDD: sudo dd if=/dev/urandom of=/dev/sdX bs=1M status=progress
        
       ___________________________________________________________________
       (page generated 2026-02-27 23:01 UTC)