Topic: A novel technique for reclaiming space after program startup.


Author: Bruce@hoult.actrix.gen.nz (Bruce Hoult)
Date: Fri, 6 Aug 1993 19:20:47 +1200 (NZST)
Raw View
rfg@netcom.com (Ronald F. Guilmette) writes:
> In many programs, a number of functions exist only for the purpose of
> getting various data structures initialized properly upon program startup.
> Following these initializations, such functions are essentially useless,
> and the space they occupy in memory is essentially wasted.  (Of course on
> systems that support paged virtual memory, this is a non-issue, but on
> other systems, such as MS-DOS, the waste of space may be troublesome.)
>
> I have just noticed an interesting way to help reduce this problem.  It
> is illustrated by the following code:
>
>  typedef void (FT) ();
>
>  void gets_destroyed () { /* ... */ }
>
>  FT *fp = gets_destroyed;
>
>  void
>  delete_init_functions ()
>  {
>   fp->~FT (); /* destruct the function */
>  }
>
> Once the initialization functions have been properly destroyed (as illustrated
> above) the space they formerly occupied may be reclaimed and used for data
> storage.
>
> Warning:  Due to bugs in some implementations, this technique is currently
> not completely portable, and the code shown above may not be accepted by
> all implementations... but many/most/all cfront-based implementations
> should accept it.
>
> :-) :-) :-)


ha ha ha.

Of course, on the Mac we can (and do) go...

 #pragma seg InitFuncs
 void gets_destroyed () { /* ... */ }

 void
 delete_init_functions ()
 {
  UnloadSeg(&gets_destroyed); /* destruct the function */
 }




Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Wed, 4 Aug 1993 20:58:01 GMT
Raw View
In many programs, a number of functions exist only for the purpose of
getting various data structures initialized properly upon program startup.
Following these initializations, such functions are essentially useless,
and the space they occupy in memory is essentially wasted.  (Of course on
systems that support paged virtual memory, this is a non-issue, but on
other systems, such as MS-DOS, the waste of space may be troublesome.)

I have just noticed an interesting way to help reduce this problem.  It
is illustrated by the following code:

 typedef void (FT) ();

 void gets_destroyed () { /* ... */ }

 FT *fp = gets_destroyed;

 void
 delete_init_functions ()
 {
  fp->~FT (); /* destruct the function */
 }

Once the initialization functions have been properly destroyed (as illustrated
above) the space they formerly occupied may be reclaimed and used for data
storage.

Warning:  Due to bugs in some implementations, this technique is currently
not completely portable, and the code shown above may not be accepted by
all implementations... but many/most/all cfront-based implementations
should accept it.

:-) :-) :-)

--

-- Ronald F. Guilmette ------------------------------------------------------
------ domain address: rfg@netcom.com ---------------------------------------
------ uucp address: ...!uunet!netcom.com!rfg -------------------------------