From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25076 invoked by alias); 4 Jul 2012 09:45:26 -0000 Received: (qmail 25001 invoked by uid 22791); 4 Jul 2012 09:45:24 -0000 X-SWARE-Spam-Status: No, hits=2.4 required=5.0 tests=AWL,BAYES_05,FSL_RCVD_USER,RCVD_IN_DNSWL_NONE,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from smtp2-g21.free.fr (HELO smtp2-g21.free.fr) (212.27.42.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 04 Jul 2012 09:45:06 +0000 Received: from www.zeusw.org (unknown [82.231.68.224]) by smtp2-g21.free.fr (Postfix) with ESMTP id 2335F4B0180 for ; Wed, 4 Jul 2012 11:44:59 +0200 (CEST) Received: from localhost ([::1] helo=zeusw.org) by www.zeusw.org with esmtp (Exim 4.72) (envelope-from ) id 1SmM8q-0003Sb-QN for cygwin@cygwin.com; Wed, 04 Jul 2012 11:45:00 +0200 Received: from 192.168.5.10 (SquirrelMail authenticated user esc) by zeusw.org with HTTP; Wed, 4 Jul 2012 11:45:00 +0200 Message-ID: <8ef10a0d4a6912c0aa23bc33eebbe95d.squirrel@zeusw.org> Date: Wed, 04 Jul 2012 09:45:00 -0000 Subject: Differences between C++ 'new' operator and 'malloc()' (NOT a C/C++ question) From: "Claude SIMON" To: cygwin@cygwin.com Reply-To: sc.cygwin.com@zeusw.org User-Agent: SquirrelMail/1.4.21 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2012-07/txt/msg00035.txt.bz2 Hello everybody ! I have some C++ code that I want to use in a native Java component compiled with Cygwin g++. I also use exactly the same C++ code in a command-line tool ('.exe' binary). When I compile the tool with Visual C++, it works. When I compile the tool with g++, it works. When I compile the component with Visual C++, it works. When I compile the component with g++... it crashes. With 'gdb', I found that the problem happens when calling the 'malloc' function (as soon as the function is called, NOT when the returned allocated memory is used). When I replace the 'malloc' by a the C++ 'new' operator, the component compiled with Cygwin g++ doesn't crash anymore. To summarize, having some code written in C++ : - used in a command line tool : - using 'malloc' : - compiled with Visual C++ : works. - compiled with Cygwin g++ : works. - used in a Java native component : - using 'malloc' : - compiled with Visual C++ : works. - compiled with Cygwin g++ : CRASHES. - using the C++ 'new' operator : - compiled with Visual C++ : works. - compiled with Cygwin g++ : works. I thought that the C++ 'new' operator calls the 'malloc' function, but this seems not to be the case. As I want to use 'malloc'-like functions rather than the C++ 'new' operator, I wonder which functions are used in the C++ 'new' operator to allocate memory (and naturally which functions are used in the C++ 'delete' operator to free the memory). If it can be of some use, the component/tool can be found at http://zeusw.org/intl/expp . The g++ version is 4.5.3. Thanks ! -- Claude SIMON (sc.CYGWIN;COM@zeusw.org) (Sorry for my poor English ; I'm French) -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple