Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c++ Subject: Re: Is this really necessary Date: Wed, 11 Aug 2021 12:54:58 -0700 Organization: A noiseless patient Spider Lines: 39 Message-ID: <867dgrzrhp.fsf@linuxsc.com> References: <86im0h2fi1.fsf@linuxsc.com> <8635rh1m2i.fsf@linuxsc.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="9b2de4ec06692993da9b82e10a905748"; logging-data="6531"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188SBnBUw1mnl6DPBJjIYgb9g9YtbmENqM=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:MO9xr7e/lAXMwSKoF8xCn5CruL4= sha1:2b8IQgFDbKcusZdKjyVqRVXEdP4= Xref: csiph.com comp.lang.c++:80856 scott@slp53.sl.home (Scott Lurndal) writes: > Tim Rentsch writes: > >> Vir Campestris writes: >> >> [..stuff about 64 bit systems removed..] >> >>> What bothers me about ptr_diff_t is the size. The difference between >>> two 32-bit pointers is plus or minus 4GB. Which needs a 33 bit value >>> :( >>> >>> As it happens it's never been a practical problem as I've never had a >>> 32 bit system with more than 2GB RAM, >> >> It isn't necessary for there to be more than 2GB of RAM for >> problems with ptrdiff_t to manifest (in 32-bit linux). A call to >> malloc() will gladly return a memory area larger than all of RAM >> if there is swap space to hold it. > > Do recall the split address space in 32-bit intel/amd systems, which > by default, limit the application to 2GB of virtual address space. > > Malloc can't return more than the available user-mode VA space > allows. Here is a data point. I have a small C program, which uses malloc() to allocate a large region of memory (once for each input file, which is processed and then the allocated memory is freed). Running the program on a 32-bit linux system (with standard amd or intel hardware), I observe malloc() successfully allocating an area larger than 2 GB. My comment above about problems with ptrdiff_t and about malloc() returning a memory area larger than all of RAM follows directly from first-hand experience. I respect your knowledge and understanding of many different operating systems. But I wasn't just talking through my hat up there.