0
Object1 * test= new Object1();

does "test" have absolute address on RAM or an absolute address in a virtual memory which has a relative starting point to RAM's zero adress?

An example could be, in a very fragmented memory I started many applications each allocating and deallocating many times for 10 hours, and one of the applications is a RAM error checking and benchmarking one. Could it test all RAM addresses or it just runs on a limited area? If it reaches all RAM, then how is OS is able to protect an app from other apps besides moving its objects? Especially when streaming non-pinned array from pci-e and to pci-e.

huseyin tugrul buyukisik
  • 11,469
  • 4
  • 45
  • 97

2 Answers2

3

Most OSes use virtual addressing, so the address seen by your program is largely independent from the physical address of the RAM itself.

Some do, however, have special functions available to allocate physical memory that has a fixed physical address. For example, on Windows you can use AllocateUserPhysicalPages to allocate some physical pages (which you can then map to/unmap from virtual addresses).

This will still only let you test a limited area though. It'll try to allocate a number of physical pages, and succeed if possible--but there are also (for example) parts of the kernel that get mapped to particular memory locations at boot, and stay there until shut down (and no method is provided to ask them to move).

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • You mean there are unusable-forever parts that serves hardware components? So ram-tester software doesn't test those parts? – huseyin tugrul buyukisik Sep 12 '16 at 20:02
  • Not necessarily serving hardware components. Just for one obvious example, things wouldn't work so well if the code that handled page faults had itself been paged out to disk. Some RAM testers run without any OS present, specifically to give them access to all the hardware. – Jerry Coffin Sep 12 '16 at 20:03
  • What if I disable virtualization from bios settings? – huseyin tugrul buyukisik Sep 12 '16 at 20:05
  • 2
    I don't know of any BIOS that would let you disable virtualization (it's part of the CPU, so it's mostly not under BIOS control), but if you could it would prevent most OSes from booting. – Jerry Coffin Sep 12 '16 at 20:07
1

It remains the same address in the virtual memory space. Which is different than the physical memory space - remember, that's what paging file is for, to be able to allocate more memory in total than the total available physical memory. Also, two different applications can get the same (virtual) memory address by calling new/malloc at the same time (but they will be indeed different addresses in the physical memory, if both are paged in at the same time).

That also means, that actually implementing an application, which tests physical memory is not trivial in system which virtualizes memory (basically all modern systems like windows, Linux etc.). And that is why many memory checking applications (like Memtest etc.) run from a bootable drive, to be able to access and utilize the physical memory directly.

Btw. note that Linux has a feature called "over-committing" (usually enabled by default), which means, that new/malloc can return a "valid" object address, but which does not correspond to any physical location at all (i.e. not yet "truly" allocated). And the memory is only allocated when something is actually written to that memory area.

EmDroid
  • 5,918
  • 18
  • 18