Re: realloc() implicit free() ?
- From: Russell Shaw <rjshawN_o@xxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 22 May 2005 09:44:52 +1000
Walter Roberson wrote:
In article <118stl2rjj6c5d5@xxxxxxxxxxxxxxxxxx>, SM Ryan <wyrmwif@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
# The question is not over-specified if one is concerned about # whether one is leaking memory. When your datasets are ~1 Gb each # and you are handling them in a loop, you can't afford to allow memory # to leak.
All you can do to prevent leaks is to match frees to allocs; you don't need to know how the library is implemented to do that much. It's still leaking you're stuck unless you can get the library source code.
That's not ALL you can do: you can also ask questions about paragraphs that one might have overlooked or which might have been clarified in addendums that one hasn't seen, which proscribe the behaviour of library routines so as to remove the ambiguity.
If no-one happens to know the answer, or if the answer is indeterminate, then one can sometimes write one's own routine that avoids the indeterminate behaviour. In the case of realloc(), since it is never -required- that the address be left unchanged, one can write a replacement for realloc() in terms of malloc(), a memory copy, and a free(), provided that one knows the current size of the object at hand.
For the address to not change, the new realloc'd size must fit in the same place. If there was occupied memory following your data and you wanted to increase the size of your data, the realloc will have to copy it all to a different location where it will fit. In this case, the address *will* change. .
- Follow-Ups:
- Re: realloc() implicit free() ?
- From: Walter Roberson
- Re: realloc() implicit free() ?
- References:
- Re: realloc() implicit free() ?
- From: Walter Roberson
- Re: realloc() implicit free() ?
- From: SM Ryan
- Re: realloc() implicit free() ?
- From: Walter Roberson
- Re: realloc() implicit free() ?
- Prev by Date: Re: Help with strings
- Next by Date: Re: Can't match char 0x10.
- Previous by thread: Re: realloc() implicit free() ?
- Next by thread: Re: realloc() implicit free() ?
- Index(es):
Relevant Pages
|