* freeing part of memory
@ 2010-01-05 1:21 £ukasz
2010-01-05 2:02 ` Thomas Martitz
0 siblings, 1 reply; 3+ messages in thread
From: £ukasz @ 2010-01-05 1:21 UTC (permalink / raw)
To: gcc-help
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: freeing part of memory
2010-01-05 1:21 freeing part of memory £ukasz
@ 2010-01-05 2:02 ` Thomas Martitz
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Martitz @ 2010-01-05 2:02 UTC (permalink / raw)
To: gcc-help
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: freeing part of memory
@ 2010-01-05 10:45 £ukasz
0 siblings, 0 replies; 3+ messages in thread
From: £ukasz @ 2010-01-05 10:45 UTC (permalink / raw)
To: gcc-help
--- On Tue, 1/5/10, £ukasz <blurrpp@yahoo.com> wrote:
> From: £ukasz <blurrpp@yahoo.com>
> Subject: Re: freeing part of memory
> To: thomas.martitz@student.htw-berlin.de
> Date: Tuesday, January 5, 2010, 11:42 AM
>
>
> --- On Tue, 1/5/10, Thomas Martitz <thomas.martitz@student.HTW-Berlin.de>
> wrote:
>
> > From: Thomas Martitz <thomas.martitz@student.HTW-Berlin.de>
> > Subject: Re: freeing part of memory
> > To: gcc-help@gcc.gnu.org
> > Date: Tuesday, January 5, 2010, 3:02 AM
> > 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.
> >
Yep i know that is strictly C question but i knew that some
one would know answer here ;). Any way free is possible to
use, but you have to cheat somehow, when you use malloc,
small structure is created wchich tells 'free', amoung
others information, how many bytes have to be freed, if u
create similar stricture in aprpriate place with changed
amount of memory to be freed, you can use free. Solution
with copy is too long so if there are no other ways, better
is to reserve big pice of memory and create for ex. in
assembler your own way to manage memory inside this.
Best regards
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-01-05 10:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-05 1:21 freeing part of memory £ukasz
2010-01-05 2:02 ` Thomas Martitz
2010-01-05 10:45 £ukasz
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).