At the end of this wikipedia article, in a section “A simple example in C” it is claimed that “the operating system delays real memory allocation until something is written into it”. From my experience this is not possible or better put, “not feasible”. An OS/Processor does not track each and every memory write. Is the wikipedia article wrong like I suspect ? If not enlighten me.
edit
I guess when one takes page faults into consideration, than it does make sense in some ways. However, page faults and virtual memory don’t fit well with a discussion on memory leaks. I mean is if process allocates 2 pages, writes to one (page one), and then leaks both pages it’s still a leak regardless of weather the second page leaks physical memory or not. I guess the section should differentiate between physical memory and virtual memory ? 😀
Depends on the operating system. On Linux, for example, it actually does work like that. Look up “optimistic memory allocation”.
In addition to that, there is the differentiation between virtual memory and physical memory. On most operating systems, you are using virtual memory, so even though you allocate many megabytes worth of memory, the actual physical memory will only be tapped once you write into it (at which point what had been at that location before might get paged back to disk).
There is the “virtual address space” which is basically just “logical” memory that is then later mapped to the physical RAM (or your hard drive, if the memory has been paged out).