Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* How do you release memory back to the kernel in C
@ 1998-05-19  4:00 Asgar Ali
  1998-05-19  4:00 ` Kaz Kylheku
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Asgar Ali @ 1998-05-19  4:00 UTC (permalink / raw)



In DEC Unix (3.x and 4.x) I am finding that "free" does not release
memory back to the kernel so that it could be used by other processes.
This creates the problem that if several such processes are running each
needed a lot of memory at some time, none of them can share what the
others have used. Hence you run out of memory quickly.

I have a simple program below which illustrates the problem.
The program allocates 10Mb, then another 10Mb, then frees the second,
then frees the first. Both frees do not release the memory back to
kernel, though the same process could reuse its free memory.

I have tried tweeking some "__xxx" memory behaviour values but to no
avail. Has anyone got any ideas? 

Asgar Ali



Program:

#include <stdlib.h>
#include <iostream.h>



#define MEMSIZE 1024*1024*10            // 10M


/*
Defaults
__noshrink      = 0
 __minshrink    = 16384
 __minshrinkfactor = 0.001000
 __mingrow      = 49152
 __mingrowfactor = 0.100000
 __madvisor     = 0
 __small_buff   = 0
 __fast_free_max = 13
 __sbrk_override = 0
*/

int main( int argc, char* argv[] )
{
        char charbuf[128];

        char c;

        void* ptr;
        void* ptr2;


        printf("Allocating memory press enter ");
        scanf("%c", &c );
        ptr = malloc( MEMSIZE );

        printf("Allocating memory press enter ");
        scanf("%c", &c );
        ptr2 = malloc( MEMSIZE );

        printf("Press enter to free it ");
        scanf("%c", &c );
        free(ptr2);

        printf("Press enter to free it ");
        scanf("%c", &c );
        free(ptr);

        printf("Press enter to exit ");
        scanf("%c", &c );
        return 0;
}



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-19  4:00 How do you release memory back to the kernel in C Asgar Ali
  1998-05-19  4:00 ` Kaz Kylheku
  1998-05-19  4:00 ` firewind
@ 1998-05-19  4:00 ` Lawrence Kirby
  1998-05-21  4:00   ` John Hascall
  2 siblings, 1 reply; 25+ messages in thread
From: Lawrence Kirby @ 1998-05-19  4:00 UTC (permalink / raw)



In article <35616C36.9167165F@citicorp.com>
           asgar.ali@citicorp.com "Asgar Ali" writes:

>In DEC Unix (3.x and 4.x) I am finding that "free" does not release
>memory back to the kernel so that it could be used by other processes.
>This creates the problem that if several such processes are running each
>needed a lot of memory at some time, none of them can share what the
>others have used. Hence you run out of memory quickly.

On a VM system unused memory teds to get moves to swap space. As long as you
don't run out of swap space it may not be a big problem. 

>I have a simple program below which illustrates the problem.
>The program allocates 10Mb, then another 10Mb, then frees the second,
>then frees the first. Both frees do not release the memory back to
>kernel, though the same process could reuse its free memory.

That is typical. The C language doesn't require that freed memory be released
in this way, indeed it provides no answer to your question. You could try
finding a replacement malloc() library that does what you want or try to
find some platfor-specific alternative. For example many Unix platforms
these days support a mmap() system function which may well provide a solution.

-- 
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-19  4:00 How do you release memory back to the kernel in C Asgar Ali
  1998-05-19  4:00 ` Kaz Kylheku
@ 1998-05-19  4:00 ` firewind
  1998-05-19  4:00 ` Lawrence Kirby
  2 siblings, 0 replies; 25+ messages in thread
From: firewind @ 1998-05-19  4:00 UTC (permalink / raw)



On Tue, 19 May 1998, Asgar Ali wrote:

> In DEC Unix (3.x and 4.x) I am finding that "free" does not release
> memory back to the kernel so that it could be used by other processes.

This is discussed in the FAQ.

-- 
(initiator of the campaign for grumpiness where grumpiness is due in c.l.c)

ftp;//rtfm.mit.edu/pub/usenet/comp.lang.c/  Read. Digest. Satori.




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-19  4:00 How do you release memory back to the kernel in C Asgar Ali
@ 1998-05-19  4:00 ` Kaz Kylheku
  1998-05-20  4:00   ` Chris Engebretson
                     ` (2 more replies)
  1998-05-19  4:00 ` firewind
  1998-05-19  4:00 ` Lawrence Kirby
  2 siblings, 3 replies; 25+ messages in thread
From: Kaz Kylheku @ 1998-05-19  4:00 UTC (permalink / raw)



On Tue, 19 May 1998 12:25:42 +0100, Asgar Ali <asgar.ali@citicorp.com> wrote:

>In DEC Unix (3.x and 4.x) I am finding that "free" does not release
>memory back to the kernel so that it could be used by other processes.

See Peter Seebach's Infrequently Asked Questions list:

6.9: I have a program which mallocs but then frees a lot of memory, but memory
usage (as reported by ps) doesn't seem to go back
down. 

     You're probably not freeing the memory completely. Try replacing 

     free(foo);

     with 

     free(foo);
     free(foo);
     free(foo);

     in case the first free() frees the memory only partially. (Unix wizards
may recognize the parallel with syncing three times before rebooting.) 

     Alternatively, free(foo) + 4; may free the remaining four bytes. (Before
using this, make sure realloc(foo, 0) returned 4). 




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-19  4:00 ` Kaz Kylheku
@ 1998-05-20  4:00   ` Chris Engebretson
  1998-05-20  4:00     ` Serguei Patchkovskii
  1998-05-24  4:00     ` Al Bowers
  1998-05-20  4:00   ` Larry Weiss
  1998-05-21  4:00   ` Asgar Ali
  2 siblings, 2 replies; 25+ messages in thread
From: Chris Engebretson @ 1998-05-20  4:00 UTC (permalink / raw)



In article <35620a04.2342689789@207.126.101.81>, 
	kaz@cafe.dot.net (Kaz Kylheku) writes:

|> On Tue, 19 May 1998 12:25:42 +0100, 
|>         Asgar Ali <asgar.ali@citicorp.com> wrote:
|> 
|> >In DEC Unix (3.x and 4.x) I am finding that "free" does not release
|> >memory back to the kernel so that it could be used by other processes.
|> 
|> See Peter Seebach's Infrequently Asked Questions list:
|> 
|> 6.9: I have a program which mallocs but then frees a lot of memory, 
|> but memory usage (as reported by ps) doesn't seem to go back down. 
|> 
|>      You're probably not freeing the memory completely. Try replacing 
|> 
|>      free(foo);
|> 
|>      with 
|> 
|>      free(foo);
|>      free(foo);
|>      free(foo);
|> 
|> in case the first free() frees the memory only partially. (Unix wizards 
|> may recognize the parallel with syncing three times before rebooting.) 

This generally works (well, better than a single bare free(), that
is) but there are more robust ways to successfully free memory.
Some Unices have a difficult time freeing large chunks of memory,
and even the triple-free() approach above doesn't always work.

What I generally recommend is freeing the block one byte at a time:

    void progressive_free(void *ptr, size_t size)
    {
	size_t i;

	for(i = size - 1; i >= 1; --i)
	    ptr = realloc(ptr, i);
	free(ptr);
    }

This gradually chops the block down to a single byte, which most
implementations of free() handle quite nicely.  (Note the obvious
safety defect in that the return of realloc() is not checked and
the original pointer value is not preserved; sanity checking is
left as an exercise to the reader.)

Regards,

-- 
Chris Engebretson - Raytheon STX Corporation | Ph#: (605)594-6829
USGS EROS Data Center, Sioux Falls, SD 57198 | Fax: (605)594-6940
http://edcwww.cr.usgs.gov/        mailto:engebret@sg1.cr.usgs.gov
Opinions are not those of  Raytheon Systems Company  or the USGS.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-20  4:00   ` Chris Engebretson
@ 1998-05-20  4:00     ` Serguei Patchkovskii
  1998-05-20  4:00       ` Kaz Kylheku
  1998-05-20  4:00       ` Larry Weiss
  1998-05-24  4:00     ` Al Bowers
  1 sibling, 2 replies; 25+ messages in thread
From: Serguei Patchkovskii @ 1998-05-20  4:00 UTC (permalink / raw)



Chris Engebretson (engebret@sg1.cr.usgs.gov) wrote:
: What I generally recommend is freeing the block one byte at a time:

Actually, real programmers never allocate memory from the kernel
at all (in part because they do not like to share their hardware
with somebody else's program, and kill the kernel as soon as they
can lay their hands on the console switches). Real programmers 
use statically dimentioned arrays, and retype the object code 
with the new size by hand when the old limit is exceeded. In this 
way, that pesky problem with releasing memory is avoided altogether.

Cheers,

/Serge.P



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-19  4:00 ` Kaz Kylheku
  1998-05-20  4:00   ` Chris Engebretson
@ 1998-05-20  4:00   ` Larry Weiss
  1998-05-21  4:00   ` Asgar Ali
  2 siblings, 0 replies; 25+ messages in thread
From: Larry Weiss @ 1998-05-20  4:00 UTC (permalink / raw)



Kaz Kylheku wrote:
> On Tue, 19 May 1998 12:25:42 +0100, Asgar Ali <asgar.ali@citicorp.com> wrote:
> >In DEC Unix (3.x and 4.x) I am finding that "free" does not release
> >memory back to the kernel so that it could be used by other processes.
> 
> See Peter Seebach's Infrequently Asked Questions list:
> 6.9: I have a program which mallocs but then frees a lot of memory,
> but memory usage (as reported by ps) doesn't seem to go back down.
>      You're probably not freeing the memory completely. Try replacing
>      free(foo);
>      with
>
>      free(foo);
>      free(foo);
>      free(foo);
>
>      in case the first free() frees the memory only partially.
> (Unix wizards may recognize the parallel with syncing three times
> before rebooting.)
> 

Kind of reminds me of the old Tony Orlando and Dawn song...which 
itself contains advice equally useful to addressing the question
at hand as this IAQ answer (as expected).

 - Larry Weiss



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-20  4:00     ` Serguei Patchkovskii
@ 1998-05-20  4:00       ` Kaz Kylheku
  1998-05-20  4:00         ` Larry Weiss
       [not found]         ` <125D9A1BA03D8776.FEF9821DB00860BE.0E4 <895712304snz@genesis.demon.co.uk>
  1998-05-20  4:00       ` Larry Weiss
  1 sibling, 2 replies; 25+ messages in thread
From: Kaz Kylheku @ 1998-05-20  4:00 UTC (permalink / raw)



On 20 May 1998 19:07:00 GMT, patchkov@acs1.acs.ucalgary.ca (Serguei
Patchkovskii) wrote:

>can lay their hands on the console switches). Real programmers 
>use statically dimentioned arrays, and retype the object code 
>with the new size by hand when the old limit is exceeded. In this 
>way, that pesky problem with releasing memory is avoided altogether.

Real programmers use functions for scratch space when they are
done calling them.




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-20  4:00     ` Serguei Patchkovskii
  1998-05-20  4:00       ` Kaz Kylheku
@ 1998-05-20  4:00       ` Larry Weiss
  1 sibling, 0 replies; 25+ messages in thread
From: Larry Weiss @ 1998-05-20  4:00 UTC (permalink / raw)



Serguei Patchkovskii wrote:
> Actually, real programmers never allocate memory from the kernel
> at all (in part because they do not like to share their hardware
> with somebody else's program, and kill the kernel as soon as they
> can lay their hands on the console switches). Real programmers
> use statically dimentioned arrays, and retype the object code
> with the new size by hand when the old limit is exceeded. In this
> way, that pesky problem with releasing memory is avoided altogether.
> 

Now you've got me all nostalgic for my FORTRAN coding days...

 - Larry Weiss



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-20  4:00       ` Kaz Kylheku
@ 1998-05-20  4:00         ` Larry Weiss
       [not found]         ` <125D9A1BA03D8776.FEF9821DB00860BE.0E4 <895712304snz@genesis.demon.co.uk>
  1 sibling, 0 replies; 25+ messages in thread
From: Larry Weiss @ 1998-05-20  4:00 UTC (permalink / raw)



Kaz Kylheku wrote:
> On 20 May 1998 19:07:00 GMT, patchkov@acs1.acs.ucalgary.ca (Serguei
> Patchkovskii) wrote:
> >can lay their hands on the console switches). Real programmers
> >use statically dimentioned arrays, and retype the object code
> >with the new size by hand when the old limit is exceeded. In this
> >way, that pesky problem with releasing memory is avoided altogether.
> 
> Real programmers use functions for scratch space when they are
> done calling them.

Really real programmers write new functions into the space
formerly occupied by the old ones.

 - Larry Weiss



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-19  4:00 ` Kaz Kylheku
  1998-05-20  4:00   ` Chris Engebretson
  1998-05-20  4:00   ` Larry Weiss
@ 1998-05-21  4:00   ` Asgar Ali
  1998-05-21  4:00     ` Kaz Kylheku
  1998-05-23  4:00     ` Gerald A. Feldman
  2 siblings, 2 replies; 25+ messages in thread
From: Asgar Ali @ 1998-05-21  4:00 UTC (permalink / raw)
  To: kaz


Sorry, 

the triple free(ptr) did not work on this DEC system.



Kaz Kylheku wrote:
> 
> On Tue, 19 May 1998 12:25:42 +0100, Asgar Ali <asgar.ali@citicorp.com> wrote:
> 
> >In DEC Unix (3.x and 4.x) I am finding that "free" does not release
> >memory back to the kernel so that it could be used by other processes.
> 
> See Peter Seebach's Infrequently Asked Questions list:
> 
> 6.9: I have a program which mallocs but then frees a lot of memory, but memory
> usage (as reported by ps) doesn't seem to go back
> down.
> 
>      You're probably not freeing the memory completely. Try replacing
> 
>      free(foo);
> 
>      with
> 
>      free(foo);
>      free(foo);
>      free(foo);
> 
>      in case the first free() frees the memory only partially. (Unix wizards
> may recognize the parallel with syncing three times before rebooting.)
> 
>      Alternatively, free(foo) + 4; may free the remaining four bytes. (Before
> using this, make sure realloc(foo, 0) returned 4).



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-19  4:00 ` Lawrence Kirby
@ 1998-05-21  4:00   ` John Hascall
  1998-05-22  4:00     ` Asgar Ali
  0 siblings, 1 reply; 25+ messages in thread
From: John Hascall @ 1998-05-21  4:00 UTC (permalink / raw)



}In article <35616C36.9167165F@citicorp.com>
}           asgar.ali@citicorp.com "Asgar Ali" writes:
}>In DEC Unix (3.x and 4.x) I am finding that "free" does not release
}>memory back to the kernel so that it could be used by other processes.
}>This creates the problem that if several such processes are running each
}>needed a lot of memory at some time, none of them can share what the
}>others have used. Hence you run out of memory quickly.

From 'man malloc' (DU 4.0d):

  Tuning Memory Allocation

  The behavior of these memory allocation functions can be tuned to optimize
  their performance in a particular application.

  The following variables control how the functions operate.  Note that these
  variables and their effects are specific to the current DIGITAL UNIX memory
  allocation implementation.  The default values for these variables are
  specified by libc.  To specify values other than the defaults, create a
  module containing definitions for the complete set of variables and include
  that module in your compilation.  (If you define only some of these vari-
  ables, your compilation will produce "multiply defined" errors if you link
  the program nonshared.)  For each variable in this list, the default value
  is indicated after the equal sign.

  unsigned long __noshrink = 0
       The variable __noshrink controls management of the heap size (which in
       turn controls the size of the required swap area).  As the user makes
       calls to free() or realloc(), the memory associated with the call can
       be put back into the pool of free memory.  Permissible values for
       __noshrink are 0 and 1.

       If the memory that is freed resides at the end of the heap and meets
       the constraints of __minshrink and __minshrinkfactor, it can be
       returned to the kernel by sbrk(nnn) if __noshrink is 0.  If __noshrink
       is 1, no attempts are made to return the freed memory.

John
-- 
John Hascall, Software Engr.        Shut up, be happy.  The conveniences you
ISU Computation Center              demanded are now mandatory. -Jello Biafra
mailto:john@iastate.edu
http://www.cc.iastate.edu/staff/systems/john/welcome.html  <-- the usual crud



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
       [not found]         ` <125D9A1BA03D8776.FEF9821DB00860BE.0E4 <895712304snz@genesis.demon.co.uk>
  1998-05-21  4:00           ` Chris Engebretson
@ 1998-05-21  4:00           ` Kaz Kylheku
  1998-05-21  4:00             ` Larry Weiss
       [not found]           ` <2DECFB7C2125FF12.8D639AF581546583.E29C243161345CFE@library-proxy.airnews.net>
  2 siblings, 1 reply; 25+ messages in thread
From: Kaz Kylheku @ 1998-05-21  4:00 UTC (permalink / raw)



On Thu, 21 May 98 00:58:24 GMT, fred@genesis.demon.co.uk (Lawrence Kirby)
wrote:

>>Really real programmers write new functions into the space
>>formerly occupied by the old ones.
>
>Formerly? They should occupy the same space simultaneously. By using a
>different entry point the same sequence of bytes can be made to represent
>a different sequence of instructions (but of course you need a real
>archetecture that doesn't have silly instruction alignment requirements).

Hey, I used to do that when programming Mostek 6502 based machines.

Mother nature also does it. There apparently exist these bacteria
whose DNA forms a ring. The protein that is formed depends on where
on the ring the decoding beings---the entry point, so to speak.
The thing is that the codings for various proteins overlap!

It's a hack and a half, not unlike overlapping machine code
instructions: in fact, worse. :)



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-21  4:00   ` Asgar Ali
@ 1998-05-21  4:00     ` Kaz Kylheku
  1998-05-23  4:00     ` Gerald A. Feldman
  1 sibling, 0 replies; 25+ messages in thread
From: Kaz Kylheku @ 1998-05-21  4:00 UTC (permalink / raw)



On Thu, 21 May 1998 09:09:29 +0100, Asgar Ali <asgar.ali@citicorp.com> wrote:

>Sorry, 
>
>the triple free(ptr) did not work on this DEC system.

In fact, it probably DEC-ked your system, right? :)




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
       [not found]         ` <125D9A1BA03D8776.FEF9821DB00860BE.0E4 <895712304snz@genesis.demon.co.uk>
@ 1998-05-21  4:00           ` Chris Engebretson
  1998-05-21  4:00           ` Kaz Kylheku
       [not found]           ` <2DECFB7C2125FF12.8D639AF581546583.E29C243161345CFE@library-proxy.airnews.net>
  2 siblings, 0 replies; 25+ messages in thread
From: Chris Engebretson @ 1998-05-21  4:00 UTC (permalink / raw)



In article <895712304snz@genesis.demon.co.uk>, 
	fred@genesis.demon.co.uk (Lawrence Kirby) writes:

|> Formerly? They should occupy the same space simultaneously. By using a
|> different entry point the same sequence of bytes can be made to represent
|> a different sequence of instructions (but of course you need a real
|> archetecture that doesn't have silly instruction alignment requirements).
|> The power of this technique can be greatly enhanced by the use of
|> self-modifying code.

Indeed!  Truly legendary applications of this technique will make 
liberal use of undocumented opcodes.

Regards,

-- 
Chris Engebretson - Raytheon STX Corporation | Ph#: (605)594-6829
USGS EROS Data Center, Sioux Falls, SD 57198 | Fax: (605)594-6940
http://edcwww.cr.usgs.gov/        mailto:engebret@sg1.cr.usgs.gov
Opinions are not those of  Raytheon Systems Company  or the USGS.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-21  4:00           ` Kaz Kylheku
@ 1998-05-21  4:00             ` Larry Weiss
  0 siblings, 0 replies; 25+ messages in thread
From: Larry Weiss @ 1998-05-21  4:00 UTC (permalink / raw)



Kaz Kylheku wrote:
> Mother nature also does it. There apparently exist these bacteria
> whose DNA forms a ring. The protein that is formed depends on where
> on the ring the decoding beings---the entry point, so to speak.
> The thing is that the codings for various proteins overlap!
> It's a hack and a half, not unlike overlapping machine code
> instructions: in fact, worse. :)

Kinda scary, isn't it, to think what kind of hacker-shop got
sub-contracted for that project...showoffs!   I wonder if "they"
ever thought that we'd find all their tricks?   

 - Larry Weiss



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-21  4:00   ` John Hascall
@ 1998-05-22  4:00     ` Asgar Ali
  0 siblings, 0 replies; 25+ messages in thread
From: Asgar Ali @ 1998-05-22  4:00 UTC (permalink / raw)



Changes to those variables settings had no affect on this problem. 
They must be on Digital's wouldn't-it-be-nice-if in future they did
something list! Try them and see, and send me the source if they work.

Asgar.

John Hascall wrote:
> 
> }In article <35616C36.9167165F@citicorp.com>
> }           asgar.ali@citicorp.com "Asgar Ali" writes:
> }>In DEC Unix (3.x and 4.x) I am finding that "free" does not release
> }>memory back to the kernel so that it could be used by other processes.
> }>This creates the problem that if several such processes are running each
> }>needed a lot of memory at some time, none of them can share what the
> }>others have used. Hence you run out of memory quickly.
> 
> From 'man malloc' (DU 4.0d):
> 
>   Tuning Memory Allocation
> 
>   The behavior of these memory allocation functions can be tuned to optimize
>   their performance in a particular application.
	...

> John
> --
> John Hascall, Software Engr.        Shut up, be happy.  The conveniences you
> ISU Computation Center              demanded are now mandatory. -Jello Biafra
> mailto:john@iastate.edu
> http://www.cc.iastate.edu/staff/systems/john/welcome.html  <-- the usual crud



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
       [not found]           ` <2DECFB7C2125FF12.8D639AF581546583.E29C243161345CFE@library-proxy.airnews.net>
@ 1998-05-22  4:00             ` CoolDoug
  1998-05-22  4:00               ` Kaz Kylheku
  1998-05-22  4:00               ` Larry Weiss
  1998-05-25  4:00             ` Rolf Magnus
  1 sibling, 2 replies; 25+ messages in thread
From: CoolDoug @ 1998-05-22  4:00 UTC (permalink / raw)



In message <2DECFB7C2125FF12.8D639AF581546583.E29C243161345CFE@library-> And
by using the "exec" instructions you can take advantage
> of code composed as a palindrome and execute it bottom to top as
> well as top to bottom.   A real space saver!  

I would like to see a radical new concept in computing that uses a simple,
analog counting system. Some kind of spatial, position-dependant method
of representing numbers... oh, thats an abacus.
---
-Doug
Insert wicked stinging satirical quote here.




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-22  4:00             ` CoolDoug
@ 1998-05-22  4:00               ` Kaz Kylheku
  1998-05-22  4:00               ` Larry Weiss
  1 sibling, 0 replies; 25+ messages in thread
From: Kaz Kylheku @ 1998-05-22  4:00 UTC (permalink / raw)



On 22 May 1998 15:39:54 GMT, cooldoug@rocketmail.com (CoolDoug) wrote:

>In message <2DECFB7C2125FF12.8D639AF581546583.E29C243161345CFE@library-> And
>by using the "exec" instructions you can take advantage
>> of code composed as a palindrome and execute it bottom to top as
>> well as top to bottom.   A real space saver!  
>
>I would like to see a radical new concept in computing that uses a simple,
>analog counting system. Some kind of spatial, position-dependant method
>of representing numbers... oh, thats an abacus.

An abacus is far from analog; it is a discrete device.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-22  4:00             ` CoolDoug
  1998-05-22  4:00               ` Kaz Kylheku
@ 1998-05-22  4:00               ` Larry Weiss
  1 sibling, 0 replies; 25+ messages in thread
From: Larry Weiss @ 1998-05-22  4:00 UTC (permalink / raw)



CoolDoug wrote:
> I would like to see a radical new concept in computing that uses
> a simple, analog counting system. Some kind of spatial,
> position-dependant method of representing numbers... oh, thats
> an abacus.


You mean slide-rule?

 - Larry Weiss



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-21  4:00   ` Asgar Ali
  1998-05-21  4:00     ` Kaz Kylheku
@ 1998-05-23  4:00     ` Gerald A. Feldman
  1 sibling, 0 replies; 25+ messages in thread
From: Gerald A. Feldman @ 1998-05-23  4:00 UTC (permalink / raw)



Asgar Ali wrote:
> 
> Sorry,
> 
> the triple free(ptr) did not work on this DEC system.
It's not supposed to. According to the ANSI C standard (4.10.3.2), if
the space has been deallocated by a call to free or realloc, the
behavior is undefined. In Digital Unix, the allocator does return memory
back to the system if it is able to. Most C allocators do not. 

-- 
 Jerry Feldman <gaf@mediaone.net>
 Boston Computer Solutions and Consulting
 http://gaf.ne.mediaone.net/



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-20  4:00   ` Chris Engebretson
  1998-05-20  4:00     ` Serguei Patchkovskii
@ 1998-05-24  4:00     ` Al Bowers
  1 sibling, 0 replies; 25+ messages in thread
From: Al Bowers @ 1998-05-24  4:00 UTC (permalink / raw)



On Wed, 20 May 1998 17:40:20 GMT, engebret@sg1.cr.usgs.gov (Chris
Engebretson) wrote:


>This generally works (well, better than a single bare free(), that
>is) but there are more robust ways to successfully free memory.
>Some Unices have a difficult time freeing large chunks of memory,
>and even the triple-free() approach above doesn't always work.
>
>What I generally recommend is freeing the block one byte at a time:
I don't see a smiley so I will make a few remarks.
>
>    void progressive_free(void *ptr, size_t size)
>    {
>	size_t i;
>
>	for(i = size - 1; i >= 1; --i)
Why size - 1, You make get unexpedted
results should the argument value of size
be 0..
>	    ptr = realloc(ptr, i);
>	free(ptr);
Why use free(). You can let realloc() do
all the work.

for(i = size; ;i--) {
   ptr = realloc(ptr,size);
   if(i== (size_t)0) break;
   }
>    }
>
>This gradually chops the block down to a single byte, which most
>implementations of free() handle quite nicely.  (Note the obvious
>safety defect in that the return of realloc() is not checked and
>the original pointer value is not preserved; sanity checking is
>left as an exercise to the reader.)
As long as size accurately represents the size of
the object, you can use this technique to 
almost totally verify that the pointer has 
been freed.

#include <stdio.h>
#include <stdlib.h>
  
#define ALLOC 10000
  
int FREE(void *p,size_t size);    
   
int main(void) {
   char *s = malloc(ALLOC);
   
   if(s == NULL) exit(EXIT_FAILURE);
   if(FREE(s,ALLOC)) {
      puts("Allocation most likely freed");
      s = NULL;
      }
   else {
      puts("Allocation was not freed");
      exit(EXIT_FAILURE);
      }
   return 0;
   }
   
int FREE(void *p,size_t size) {
   size_t i;
   void *temp;

   for(i = size ; ;--i) {
      temp = realloc(p,i);
      if(i == (size_t)0) return 1;
      if(temp == NULL) return 0;
      p = temp;
      }
   }    
Al Bowers                                
Tampa, FL
mailto: abowers@combase.com
http://www.gate.net/~abowers/index.html



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
       [not found]           ` <2DECFB7C2125FF12.8D639AF581546583.E29C243161345CFE@library-proxy.airnews.net>
  1998-05-22  4:00             ` CoolDoug
@ 1998-05-25  4:00             ` Rolf Magnus
  1998-05-25  4:00               ` Larry Weiss
  1998-05-29  4:00               ` Patrick M.
  1 sibling, 2 replies; 25+ messages in thread
From: Rolf Magnus @ 1998-05-25  4:00 UTC (permalink / raw)



Larry Weiss wrote:

 > And by using the "exec" instructions you can take advantage
 > of code composed as a palindrome and execute it bottom to top as
 > well as top to bottom.   A real space saver!

How about a magic square where you can run horizontal, vertical and
diagonal functions in some sort of 2- or more-dimensional array of
instructions?



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-25  4:00             ` Rolf Magnus
@ 1998-05-25  4:00               ` Larry Weiss
  1998-05-29  4:00               ` Patrick M.
  1 sibling, 0 replies; 25+ messages in thread
From: Larry Weiss @ 1998-05-25  4:00 UTC (permalink / raw)



Rolf Magnus wrote:
> Larry Weiss wrote:
>  > And by using the "exec" instructions you can take advantage
>  > of code composed as a palindrome and execute it bottom to top as
>  > well as top to bottom.   A real space saver!
> 
> How about a magic square where you can run horizontal, vertical and
> diagonal functions in some sort of 2- or more-dimensional array of
> instructions?

Why not?  After all, you have control when indirectly exec'ing.

 - Larry Weiss



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: How do you release memory back to the kernel in C
  1998-05-25  4:00             ` Rolf Magnus
  1998-05-25  4:00               ` Larry Weiss
@ 1998-05-29  4:00               ` Patrick M.
  1 sibling, 0 replies; 25+ messages in thread
From: Patrick M. @ 1998-05-29  4:00 UTC (permalink / raw)



How about:


#include <stdio.h>
main ()
{
 int i;
 char mem[500000];
 for (i=0;i<500000;i++)
	mem[i]=0;
 exit(0);
}





"Marlboro Lights   || Patrick Mendoza
  and just 	   || De Anza Community College, Cupertino, Ca
  another kid."    || Computer Science Undergrad.



^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~1998-05-29  4:00 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-05-19  4:00 How do you release memory back to the kernel in C Asgar Ali
1998-05-19  4:00 ` Kaz Kylheku
1998-05-20  4:00   ` Chris Engebretson
1998-05-20  4:00     ` Serguei Patchkovskii
1998-05-20  4:00       ` Kaz Kylheku
1998-05-20  4:00         ` Larry Weiss
     [not found]         ` <125D9A1BA03D8776.FEF9821DB00860BE.0E4 <895712304snz@genesis.demon.co.uk>
1998-05-21  4:00           ` Chris Engebretson
1998-05-21  4:00           ` Kaz Kylheku
1998-05-21  4:00             ` Larry Weiss
     [not found]           ` <2DECFB7C2125FF12.8D639AF581546583.E29C243161345CFE@library-proxy.airnews.net>
1998-05-22  4:00             ` CoolDoug
1998-05-22  4:00               ` Kaz Kylheku
1998-05-22  4:00               ` Larry Weiss
1998-05-25  4:00             ` Rolf Magnus
1998-05-25  4:00               ` Larry Weiss
1998-05-29  4:00               ` Patrick M.
1998-05-20  4:00       ` Larry Weiss
1998-05-24  4:00     ` Al Bowers
1998-05-20  4:00   ` Larry Weiss
1998-05-21  4:00   ` Asgar Ali
1998-05-21  4:00     ` Kaz Kylheku
1998-05-23  4:00     ` Gerald A. Feldman
1998-05-19  4:00 ` firewind
1998-05-19  4:00 ` Lawrence Kirby
1998-05-21  4:00   ` John Hascall
1998-05-22  4:00     ` Asgar Ali

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox