Re: Optimize causes an error.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



LWATCDR schrieb:

And now for a simple question. How the heck to I find out how much
free memory I have in c?
None of the programmers at my office know because we haven't needed to
check for free memory for many years.

Unfortunately this isn't actually a simple question. On all modern operating systems, memory is a highly virtualized resource. From the viewpoint of a single process, a concept such as "free memory" just does not exist, there is just free address space.

You looking for the available physical RAM?
Well, this should be close to zero on a good OS; such OS tries to use all unused physical memory for caching and buffering and frees it on demand, that is, if there is a better purpose to use it.

You are looking for the available virtual memory?
Well, this is, in theory, only limited by the size of your address space. Thus, you have four GB on a 32bit architecture. The upper one or two GB are typically used by the OS itself.

You are looking for the available memory on the C heap?
Well, this is, again, just limited by the available address space. On most systems the heap starts with 1 MB of address space, but is expanded by the OS/C library on demand.

Moreover, most OS implement working set policies, effectively restricting the amount of phyiscal RAM that can be used by a single process. However, working sets are highly dynamical, the OS expands and trims them depending on load, access characteristics and so on.

As you can see, all this has almost nothing to do with C. It is a highly OS-specific thing.

Daniel


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux