[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
 

Re: [CPROG] Fri hukommelse og store arrays



On Mon, 13 Dec 1999, Martin E. Nielsen wrote:

> Jeg sidder og skal til at lave nogle store double arrays i C++, men hvordan
> checker jeg om der er hukommelse nok?

Det kan du ikke rigtig -- og Linux vil endda lade dig allokere mere
virtuel hukommelse end der er fysisk tilgængeligt (aka "overcommit") og
først give fejl når hukommelsen faktisk ER i brug. (med mindre du bruger
ulimit til at sætte en begrænsning på X megabyte virtuel hukommelse)

Man kan vist slå overcommit fra på nyere kerner. Så vil din malloc
returnere NULL, og hvis du bruger new vil den vel kaste en exception (jeg
har aldrig oplevet det :P)

Hvis du virkelig vil kan du prøve at indlæse filen /proc/meminfo og parse
output af den. Men "MemFree" der betyder spildt hukommelse, hukommelse der
ikke er i brug overhovedet. Linux vil prøve at benytte al det hukommelse
der er tilgængeligt til disk cache, og når du så allokere og bruger noget
hukommelse i et program vil der blive flyttet noget fra cachen til dit
program.



-- 
==============================================================================
Erwin Andreasen   Herlev, Denmark <sslug@sslug>          UNIX System Programmer
<URL:http://www.andreasen.org>              <*>         (not speaking for) DDE
==============================================================================



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 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] *