delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/04/29/10:56:19

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
From: Chris Faylor <cgf AT cygnus DOT com>
Date: Thu, 29 Apr 1999 10:50:50 -0400
To: cygwin <cygwin AT sourceware DOT cygnus DOT com>
Subject: Re: malloc and free mixing in VC++ and cygwin
Message-ID: <19990429105050.A772@cygnus.com>
References: <09e101be923b$a1f44aa0$e63d2509 AT jonpryor DOT raleigh DOT ibm DOT com>
Mime-Version: 1.0
X-Mailer: Mutt 0.95.3i
In-Reply-To: <09e101be923b$a1f44aa0$e63d2509@jonpryor.raleigh.ibm.com>; from Jonathan Pryor on Thu, Apr 29, 1999 at 08:26:48AM -0400

On Thu, Apr 29, 1999 at 08:26:48AM -0400, Jonathan Pryor wrote:
>Maybe. :)
>
>More precisly, can `malloc' be used to allocate memory in cygwin
>and `free' be used in VC to free the cygwin-allocated memory?
>No -- they use different memory schemes.
>
>However, that doesn't mean that you can't have one environment
>allocate memory, and have the other free it -- you just can't
>use the C runtime functions.
>
>The Win32 functions CoTaskMemAlloc() and CoTaskMemFree() can
>be used to allocate/free memory between 2 otherwise incompatible
>memory schemes.  I suspect that most of the other Win32 memory
>functions (GlobalAlloc/GlobalFree, etc.) could also be used
>to do this as well.

You could use these routines to free the memory but you'd end
up with a severely corrupted heap as far as cygwin is concerned.
Cygwin's free() command does more than (potentially) return memory
to the system.  In fact, it usually doesn't even return memory to
the system.  It also keeps a list of all allocated memory for reuse
by other malloc calls.  This is a pretty standard way of doing things.

I'd suggest just using straight Windows routines for doing memory
allocation and deallocation if you have this requirement.

-chris

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019