public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Martitz <thomas.martitz@student.HTW-Berlin.de>
To: gcc-help@gcc.gnu.org
Subject: Re: freeing part of memory
Date: Tue, 05 Jan 2010 02:02:00 -0000	[thread overview]
Message-ID: <4B429DAA.4010009@htw-berlin.de> (raw)
In-Reply-To: <176738.14678.qm@web50304.mail.re2.yahoo.com>

Am 05.01.2010 02:21, schrieb £ukasz:
> Hi, i have simple question about freeing only part of allocated memory.
> Supouse that at begining of computatnion i reserwed ( malloc,relloc, etc) n bytes, after end of compuation i need only n/2 bytes so i want to free the rest of n/2 bytes. I could ofcourse use freeloc(beg.adress+n/2) after creating in memory apropriate structure usualy created by malloc to force freeloc to free only n/2 bytes, but maybe there is another way, for example using new and delate.
>
> Lukas
>
>
>
>    

You use realloc with n/2. This will (very likely) in fact allocate in a 
new ram area, so you possibly want to copy over the data from the old 
allocated space. If you are done with the space you allocated first, you 
free the whole thing.

You cannot use "freeloc(beg.adress+n/2) " (assuming you mean free() here).

That's really a general C question, not a gcc related one.

Best regards.

  reply	other threads:[~2010-01-05  2:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-05  1:21 £ukasz
2010-01-05  2:02 ` Thomas Martitz [this message]
2010-01-05 10:45 £ukasz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B429DAA.4010009@htw-berlin.de \
    --to=thomas.martitz@student.htw-berlin.de \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).