* Question on 'realloc' function
@ 1997-09-18 4:00 Joe Spanicek
1997-10-01 4:00 ` Al Simons
0 siblings, 1 reply; 2+ messages in thread
From: Joe Spanicek @ 1997-09-18 4:00 UTC (permalink / raw)
Hi,
I hope there will be someout out there who could help.
I have a question regarding the 'realloc' function on Digital Unix V4.0.
I have read the man page but it is not that clear on a certain points.
If a call to 'realloc' fails and returns a NULL to indicate it has,
what actually happens to the original memory block passed as a pointer
reference into the function ??
1) Does it get free'd ??
2) Or is the original memory block left intact and can
subsequently be used ??
3) Or at some point when it fails, can the memory block
get corrupted and you do not know whether it can be used ??
The reason I ask, is that in a certain application, large emounts of
memory are realloc'd. When this fails I would like to free the
original memory block and let the application continue as normal.
Thanks for any help.
Joe Spanicek
joe@resptk.bhp.com.au
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Question on 'realloc' function
1997-09-18 4:00 Question on 'realloc' function Joe Spanicek
@ 1997-10-01 4:00 ` Al Simons
0 siblings, 0 replies; 2+ messages in thread
From: Al Simons @ 1997-10-01 4:00 UTC (permalink / raw)
To: Joe Spanicek
Joe Spanicek wrote:
> If a call to 'realloc' fails and returns a NULL to indicate it has,
> what actually happens to the original memory block passed as a pointer
> reference into the function ??
When a call to realloc fails and returns NULL, the original has not been
modified. It ia available to the application to continue processing as
the application sees fit.
Some caveats:
When the application calls realloc(old, 0) this is considered a synonym
for free(old). realloc() returns NULL, and the old memory is free.
When free is called on a chunk of memory 632 bytes or smaller, it is
placed in a special way station for one additional free operation.
While it is in the waystation, it can be successfully realloc'd. THIS
IS NOT SUGGESTED PRACTICE! This is a hack to accommodate a large class
of buggy programs. There is no waystation for blocks above 632 bytes in
size. Once freed, they have had portions of the block overwritten with
bookkeeping information. In the first case (<= 632 bytes), the realloc
can succeed. In the latter case (>632 bytes) the realloc will fail, the
memory pointed to by your pointer has not been touched by the realloc
operation, but it HAS ALREADY BEEN MODIFIED by the free operation.
Al Simons
DIGITAL UNIX Development Environment
simons@zk3.dec.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1997-10-01 4:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-09-18 4:00 Question on 'realloc' function Joe Spanicek
1997-10-01 4:00 ` Al Simons
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox