www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How about use Gc as a big memory pool?

reply Dsby <dushibaiyu yahoo.com> writes:
when the soft start, call GC.disable().
use "new " create a class , struct or a array. and use 
destory(T/void *) to call the ~this(), then GC.free to free the 
memory, and use RAII in class or Struct.
And user the Timer, or in some where to call : GC.enable(), 
GC.collect(), GC.disable();

In this way , i can know and control when is GC runing.

Is This way   feasible? will It  have a problem?
Apr 07 2016
parent reply Olivier Pisano <olivier.pisano supersonicimagine.com> writes:
On Friday, 8 April 2016 at 03:27:04 UTC, Dsby wrote:
 when the soft start, call GC.disable().
 use "new " create a class , struct or a array. and use 
 destory(T/void *) to call the ~this(), then GC.free to free the 
 memory, and use RAII in class or Struct.
 And user the Timer, or in some where to call : GC.enable(), 
 GC.collect(), GC.disable();

 In this way , i can know and control when is GC runing.

 Is This way   feasible? will It  have a problem?
It should work, but you cannot predict how much time collect() will take, since it depends on the system state (how much work it has to do). So instead of calling it at fixed intervals, you'd better call it when your application is idle. Why don't you try to use https://dlang.org/phobos/std_experimental_allocator.html ?
Apr 07 2016
parent Dsby <dushibaiyu yahoo.com> writes:
On Friday, 8 April 2016 at 05:31:10 UTC, Olivier Pisano wrote:
 On Friday, 8 April 2016 at 03:27:04 UTC, Dsby wrote:
 when the soft start, call GC.disable().
 use "new " create a class , struct or a array. and use 
 destory(T/void *) to call the ~this(), then GC.free to free 
 the memory, and use RAII in class or Struct.
 And user the Timer, or in some where to call : GC.enable(), 
 GC.collect(), GC.disable();

 In this way , i can know and control when is GC runing.

 Is This way   feasible? will It  have a problem?
It should work, but you cannot predict how much time collect() will take, since it depends on the system state (how much work it has to do). So instead of calling it at fixed intervals, you'd better call it when your application is idle. Why don't you try to use https://dlang.org/phobos/std_experimental_allocator.html ?
It work. before 2.071, in the ~this call GC.free will Erro. now it is fine. I know and used experimental_allocator. but new is better than theAllocator.make!(), in read, and write.
Apr 08 2016