forum.alglib.net
http://forum.alglib.net/

Combining the *_destroy() and *_clear() routines.
http://forum.alglib.net/viewtopic.php?f=2&t=3949
Page 1 of 1

Author:  RockBrentwood [ Tue Mar 05, 2019 10:48 pm ]
Post subject:  Combining the *_destroy() and *_clear() routines.

In my copy of ALGLIB, I combined the T_destroy() and T_clear() routines, for all the object types T, into T_free(void *ptr, ae_bool make_automate) with T_clear(...) = T_free(..., ae_true) and T_destroy(...) = T_free(..., ae_false). The name of extra parameter is justified by the fact that it is used in the same way as it is for the T_init(...) and T_init_copy(...) routines: ae_false for global objects and ae_true for local objects that go on the frame.

In the process of doing this, I ran into (but successfully resolved) a few problems that you probably encountered. You may be able to use this in your version.
(1) The destroy() functions are declared as members in ae_smart_ptr and ae_shared_pool. These I change to void (*destroy)(void *ptr, ae_bool make_automatic).
(2) It is also declared as a member in void (*deallocator)(void *ptr) in ae_dyn_block. This is kept the same.
(3) Instances of T_{clear/destroy}(...) are replaced by T_free(..., make_automatic) where the definitions of T_clear() and T_destroy() are merged into the definition of T_free().
(4) Instances of T_clear(...) are replaced by T_free(..., ae_true); and T_destroy(...) by T_free(..., ae_false), wherever they occur.
(5) Instances of calls to the destroy(...) field are replaced by calls to free(..., ae_false)
(6) ae_db_free(), ae_free_lock() do *not* get the extra parameter make_automatic, but ae_{vector,matrix,smart_ptr}_{destroy,clear}() do and are combined into ae_{vector,matrix,smart_ptr}_free().
(7) A dummy routine for ae_smart_ptr_destroy(...) = ae_smart_ptr_free(..., ae_false) is declared for use as the deallocator field of ae_dyn_block ... which happens once in ae_shared_pool_init().
(8) The routine ae_shared_pool_internalclear() also gets the make_automatic parameter; it is passed on as the extra parameter when the member field dst->destroy(...) is replaced by dst->free(..., make_automatic).
(9) It is invoked as ae_shared_pool_internalclear(..., make_automatic) in the definition of ae_shared_pool_free(..., make_automatic) (which replaced the definitions of ae_shared_pool_{clear/destroy}()), but as ae_shared_pool_internalclear(..., ae_false) in the definitions of ae_shared_pool_set_seed() and ae_shared_pool_reset().

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/