How to get the amount of virtual memory in C ++?

I would like to map a file in memory using the mmap function and would like to know if there is enough virtual memory on the current platform to display a huge file. For the 32nd system, I cannot match a file larger than 4 GB.
Will it std::numeric_limits<size_t>::max()indicate the amount of address memory or some other type that I should check (off_t or something else)?

As Lee Ryan noted in his comment, “virtual memory” is used incorrectly here. However, the question is: there is a type associated with the pointer, and it has a maximum value that defines the upper limit of what you can specify in your system. What type is this? Is it size_t or maybe ptrdiff_t?

+3
source share
5 answers

size_tonly required to be large enough to store the largest possible single continuous object. This may not be the same as the size of the address space (for example, for systems with a segmented memory model)

However, on regular flat memory platforms, they are equal, so in practice, if you know the target processor, you can avoid using it size_t.

, . , 32- 4 , size_t - 32- . , . . : ( , ), , ..

, , size_t, , , . , , . , , , 100 . , 32- , , . ( WhatIsTheLargestPossibleMemoryAllocationICanMake() API, . , . , - , .

, , , , .

+1

, GlobalMemoryStatusEx VirtualQueryEx, win32

+1

, , " " , .. .

:

  • . , (, , , , ).
  • . Linux/UNIX "ulimit" . setrlimit() , Windows .
  • . , , "" .
  • . ""; 64 x86, , 0x0.xxfffffffffff 0xffff000000000000 0xffffffffffffffffff. 2x128TB 16EB. 48- "" ...

, " " " ". malloc (someBigSize) mmap (..., someBigSize,...), , .

UNIX getrlimit (RLIMIT_AS), - , / . , , .

+1

" , ", ; . 64- (x64, sparc), MMU (uintptr_t) (- 1) , .. - 64- . , , ...

" " () . , , Solaris Linux. getrlimit (RLIMIT_AS) .

, , , , () , , . "" "" , . 64- , , "/" , .

+1

sizeof(int*). ( ) . , , .

0
source

Source: https://habr.com/ru/post/1775634/


All Articles