[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

C++ && Hukommelse



Er dér nogen af jer, der kender en standardiseret maade for nogenlunde at
finde ud af, hvor meget hukommelse en process kan bruge uden at systemet
begynder at swappe?

Det er klart, at det ikke kan lade sig gøre med 100% sikkerhed, da
hukommelsesforbrug er en dynamisk størrelse og processen ikke selv
har den store indflydelse paa swapping (untagen hvis man locker
memory pages til physisk hukommelse, hvad jeg ikke vil).

Saadan noget kan f.eks. bruges til at bygge memory caches. Man vil jo
ikke have, at éns cache bliver swapped ud, vel.

Det virker med sysconf, dog ser dette ikke ud til at være en standardiseret
maade. getrlimit virker ikke med nyere kerne og er ikke standard, heller.

Hans-Christian Stadler
----------------------------------------------------------------
Pa en boks med 700MB faar jeg:
TOTAL MEM: 793190400
AVAIL MEM: 483004416
MAX RESIDENT SET: 4294967295    <-- total ude i vejret!!
RESIDENT SET: 4294967295        <-- total ude i hampen!!
----------------------------------------------------------------
#include <sys/resource.h>
#include <cstdlib>
#include <cerrno>
#include <iostream>

using namespace std;

int main (int argc, char *argv[])
{
        long page_sz = sysconf(_SC_PAGESIZE);
        long n_pages = sysconf(_SC_PHYS_PAGES);         // <-- Nonstandard
        long avail_pages = sysconf(_SC_AVPHYS_PAGES);   // <-- Nonstandard
        unsigned long long tot_mem, avail_mem;

        if ((page_sz > 0) && (n_pages > 0)) {
                tot_mem = page_sz * n_pages;
                avail_mem = page_sz * avail_pages;
        } else
                cerr << "Error: Bogus sysconf values." << endl, exit(1);

        cout << "TOTAL MEM: " << tot_mem << endl <<
                "AVAIL MEM: " << avail_mem << endl;

        struct rlimit rlim;
        if (getrlimit(RLIMIT_RSS, &rlim))               // <-- BSD specific
                cerr << "Error: " << strerror(errno) << endl, exit(1);

        cout << "MAX RESIDENT SET: " << rlim.rlim_max << endl;

        return 0;
}



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-04-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *