using D without GC

2015-06-07 Thread Oleg B via Digitalmars-d-learn
Hello. I want to try use D without GC and I'm not sure what I do all right. import core.memory; version( gcdis ) enum gc_disable = true; else enum gc_disable = false; class Foo { byte[][] buf; this() { foreach( i; 0 .. 32 ) buf ~= new byte[]( 65536 *

Re: using D without GC

2015-06-07 Thread Rikki Cattermole via Digitalmars-d-learn
On 7/06/2015 10:16 p.m., Oleg B wrote: Hello. I want to try use D without GC and I'm not sure what I do all right. import core.memory; version( gcdis ) enum gc_disable = true; else enum gc_disable = false; class Foo { byte[][] buf; this() { foreach( i; 0 ..

Re: using D without GC

2015-06-07 Thread Oleg B via Digitalmars-d-learn
No just reserve some memory and preallocate the buffer you want before using it. It'll be a lot faster and cheaper. I know, it's only for test. You shouldn't be using delete or new for that matter. You should be using malloc + free. And emplace. auto myalloc(T)( size_t count ) { struct Im

Re: using D without GC

2015-06-07 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 7 June 2015 at 16:25:29 UTC, Oleg B wrote: auto myalloc(T)( size_t count ) { struct Impl{ size_t len; void* ptr; } union Wrap { Impl impl; T[] arr; } auto ret = Wrap( Impl( count, calloc( count, T.sizeof ) ) ).arr; enforce( ret.ptr !is null ); return ret; } No

Re: using D without GC

2015-06-07 Thread thedeemon via Digitalmars-d-learn
On Sunday, 7 June 2015 at 10:23:22 UTC, Rikki Cattermole wrote: Don't worry about collecting at the end. The OS will clean up the app no matter what. Actually D runtime will also do a collection before exiting. This is why it shows "Number of collections: 2" above. One triggered manually, on

Re: using D without GC

2015-06-08 Thread Mike via Digitalmars-d-learn
On Sunday, 7 June 2015 at 10:16:36 UTC, Oleg B wrote: Hello. I want to try use D without GC and I'm not sure what I do all right. You may want to take a look at this Wiki page. It has several patterns managing memory without the GC: http://wiki.dlang.org/Memory_Management Mike

Re: using D without GC

2015-06-08 Thread Andrea Fontana via Digitalmars-d-learn
On Sunday, 7 June 2015 at 16:25:29 UTC, Oleg B wrote: No just reserve some memory and preallocate the buffer you want before using it. It'll be a lot faster and cheaper. I know, it's only for test. You shouldn't be using delete or new for that matter. You should be using malloc + free. And emp

Re: using D without GC

2015-06-08 Thread Oleg B via Digitalmars-d-learn
I guess you should follow andrei's post about new allocators! Can you get link to this post?

Re: using D without GC

2015-06-08 Thread Oleg B via Digitalmars-d-learn
I guess you should follow andrei's post about new allocators! Did you mean this article http://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation ?

Re: using D without GC

2015-06-08 Thread via Digitalmars-d-learn
On Monday, 8 June 2015 at 12:24:56 UTC, Oleg B wrote: I guess you should follow andrei's post about new allocators! Can you get link to this post? These are some of his posts: http://forum.dlang.org/thread/mku0n4$s35$1...@digitalmars.com http://forum.dlang.org/thread/mkl1eh$1mdl$2...@digital

Re: using D without GC

2015-06-08 Thread Oleg B via Digitalmars-d-learn
On Monday, 8 June 2015 at 13:37:40 UTC, Marc Schütz wrote: On Monday, 8 June 2015 at 12:24:56 UTC, Oleg B wrote: I guess you should follow andrei's post about new allocators! Can you get link to this post? These are some of his posts: http://forum.dlang.org/thread/mku0n4$s35$1...@digitalmar

Re: using D without GC

2015-06-09 Thread via Digitalmars-d-learn
On Monday, 8 June 2015 at 20:11:31 UTC, Oleg B wrote: On Monday, 8 June 2015 at 13:37:40 UTC, Marc Schütz wrote: On Monday, 8 June 2015 at 12:24:56 UTC, Oleg B wrote: I guess you should follow andrei's post about new allocators! Can you get link to this post? These are some of his posts: h