Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-MimeOLE: Produced By Microsoft Exchange V6.0.6375.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Subject: RE: finding out how much memory is available with malloc, gcc, cygwin Date: Tue, 19 Aug 2003 11:26:22 +0530 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: From: "Kiran Bacche" To: "Jim Holder" , X-OriginalArrivalTime: 19 Aug 2003 05:56:22.0889 (UTC) FILETIME=[9E5FAD90:01C36616] Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id h7J5umh05436 Hi Jim Well in almost all current Oses, each application is allocated a virtual memory of 2^32 Bytes. This block is divided into many segments like data, text, bss, stack and heap. The max. size of heap depends varies from one application to another as the other segments vary from one application to another. And also it is OS dependent. Some OS may restrict it's heap from growing beyond some MBs, and some may allow applications to readjust the heap size. (thru calls similar to unix brk() call). OK that's some theory. Coming to your applciation, if the intent is to find out the "physical memory" present, I think some kernel level programming is required. Please refer "Linux Device Drivers" By Rubini of the O'Reilly Team. But if the intent is to really find out how many bytes can be malloced by an application, I think the answer will be different on different Oses. Hope this helps. Cheers Kiran -----Original Message----- From: Jim Holder [mailto:j_r_holder AT yahoo DOT com] Sent: Tuesday, August 19, 2003 3:25 AM To: cygwin AT cygwin DOT com Subject: finding out how much memory is available with malloc, gcc, cygwin A program similar to the one listed below works for me on Linux but not under Cygwin. The idea is to find out how memory I can allocate on the machine. The Cygwin version keeps going (past 700MB), reporting that it has allocated more memory than the machine has. What am I doing wrong? Thanks. #include #include int main(void) { char *p; int loop = 1; long allocated = 0L; const long PIECE = 1000L; const long TENMB = 10000000L; long nextTenMB = TENMB; while(loop) { p = (char*)malloc(PIECE); if(p == NULL) { printf("p == NULL\n"); loop = 0; } if(p == (char*)0) { printf("p == (char*)0\n"); loop = 0; } if(loop == 0) break; allocated += PIECE; if(allocated >= nextTenMB) { printf("%ld\n", allocated); nextTenMB += TENMB; } } printf("final: %ld\n", allocated); return 0; } Some environment particulars: - cygwin 1.3.19-1 - gcc 3.2-3 - windows 2000, version 5.0, service pack 4 __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ **************************Disclaimer************************************ Information contained in this E-MAIL being proprietary to Wipro Limited is 'privileged' and 'confidential' and intended for use only by the individual or entity to which it is addressed. You are notified that any use, copying or dissemination of the information contained in the E-MAIL in any manner whatsoever is strictly prohibited. *************************************************************************** -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/