X-Spam-Check-By: sourceware.org From: "Dan Stratila" To: Subject: malloc/new allocate twice as much? Date: Fri, 30 Dec 2005 18:12:30 -0500 Message-ID: <001e01c60d96$82fc34e0$43055f12@somerville> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_001F_01C60D6C.9A262CE0" X-Spam-Score: -1.215 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 Note-from-DJ: This may be spam ------=_NextPart_000_001F_01C60D6C.9A262CE0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hi, This is an issue I've discovered and reproduced while trying to compile polymake (see the thread "gcc crash (memory?)"). It seems that both malloc and new allocate take up twice the amount of memory needed. I wrote a short program to allocate and use memory in chunks (mem-test.cpp), and compiled it with g++ 3.4.4. I monitored it using the Windows Task Manager. When asked to allocate 100MB in increments of 10MB, the process size goes to 100MB and then drops to 0, as expected. However, the total commit charge for the machine goes up by 200MB, and then drops back! One might think it's a harmless bug in Task Manager, but the problem is that the total commit limit for the machine is 2GB, and I ask mem-test for 1.1GB of memory, then it is unable to obtain the last 100-200MB (and Windows complains about low memory as well). The problem seems to occur with both malloc and new. The same program compiled with MS Visual C++ behaves normally. I am able to get 1.1GB, and both the process size, and the total commit charge are as expected. I have reproduced this bug on another machine, also running Windows XP SP2, with a fresh Cygwin install. The cygwin.out for my machine is the same as for the "gcc crash (memory?)" thread, but I re-attach it in any case. Sincerely, Dan ------=_NextPart_000_001F_01C60D6C.9A262CE0 Content-Type: text/plain; name="mem-test.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="mem-test.cpp" /* $Name: $ $Id: mem-test.cpp,v 1.3 2005/12/30 23:09:55 dstrat Exp $ mem-test tests how much RAM an application can get. Usage: mem-test <# chunks> . */ #include #include using namespace std; int main(int, char* argv[]) { int *p, i, iMax=0, j, k, numChunks, chunkSize; numChunks=atoi(argv[1]); chunkSize=atoi(argv[2]); cout << "mem-test: numChunks=" << numChunks << ", chunkSize=" << chunkSize << "." << endl; cout << "mem-test: Allocating: " << flush; for (i=0;i