I'm trying to implement a standard gsl_rng_type that is
backed by a file.  The file should be opened when the
gsl_rng is created, a clone needs to dup() the file handle
and copy the file offset, and the file needs to be closed
when gsl_rng_free() is called.

For rng creation, gsl_rng_alloc() calls gsl_rng_type->set()
with a freshly malloc()ed "state" area.  Since the area is
uninitialized memory, one can't use it directly as a flag to
see if set() has been called before on this particular
rng_type.

Cleanup is also a problem.  The gsl_rng_free() directly
calls free() on both the state and gsl_rng itself.  This
means there is no obvious way to force the close needed to
clean up after a file-backed rng.

I don't see any clean way of implementing something like
this without adding a callback or two to gsl_rng_type.

Something like this might work:

typedef struct
  {
     gsl_rng_type base
     void* create_state(const void* clone);
     destroy_state(void* state);
  }
gsl_rng_extended_type;

The argument to create_state() would let the code
distinguish between a new state object (NULL == clone) and
one being created through a call to gsl_rng_clone() (NULL !=
clone).

The library code could default to the old behavior if size >
0, but use the new callbacks if 0 == size.  (Are there any
existing implementations that have a zero size?)


Any thoughts on this matter?


Thanks.



_______________________________________________
Help-gsl mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gsl

Reply via email to