[comp.lang.c] Return segment to OS

gd010gd02@mdcbbs.com (04/23/91)

	It appears that the memory requested from the operating
	system by malloc() is never released even after all the
	entries in the allocated segment have been free()'ed
	Does anyone know of a "safe" way of returning a segment
	to the operating system?

henry@zoo.toronto.edu (Henry Spencer) (04/23/91)

In article <1991Apr22.100300.1367@mdcbbs.com> gd010gd02@mdcbbs.com writes:
>	It appears that the memory requested from the operating
>	system by malloc() is never released even after all the
>	entries in the allocated segment have been free()'ed
>	Does anyone know of a "safe" way of returning a segment
>	to the operating system?

Which operating system?  There is certainly no *portable* way of doing this,
so you would be better off asking this question in an operating-system group
like comp.os.msdos.programmer.
-- 
And the bean-counter replied,           | Henry Spencer @ U of Toronto Zoology
"beans are more important".             |  henry@zoo.toronto.edu  utzoo!henry

torek@elf.ee.lbl.gov (Chris Torek) (04/23/91)

In article <1991Apr22.100300.1367@mdcbbs.com> gd010gd02@mdcbbs.com writes:
>It appears that the memory requested from the operating system by
>malloc() is never released even after all the entries in the allocated
>segment have been free()'ed.  Does anyone know of a "safe" way of
>returning a segment to the operating system?

Yes, you make a SYS$RELEASE_SEGMENT call.

No, actually, you call sbrk.

No, no, no, the *right* way is to . . .   :-)

The words `operating system' are a bit hint: this question belongs on
an O/S specific newsgroup (preferably one for the O/S in question).

Note that there is usually no reason malloc() cannot be coded to give
space back to the O/S, but it is sometimes tricky to get this right.
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA		Domain:	torek@ee.lbl.gov

gwyn@smoke.brl.mil (Doug Gwyn) (04/24/91)

In article <1991Apr22.100300.1367@mdcbbs.com> gd010gd02@mdcbbs.com writes:
-	It appears that the memory requested from the operating
-	system by malloc() is never released even after all the
-	entries in the allocated segment have been free()'ed
-	Does anyone know of a "safe" way of returning a segment
-	to the operating system?

You didn't say WHICH operating system, but the generic answer is:
"No, if the malloc/free implementation doesn't take care of this it
would be folly for your application program to try to."