www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - nogc for structs, blocks or modules?

reply maik klein <maikklein googlemail.com> writes:
I am probably the minority but I almost never use the GC in D. 
Because I never use the GC I could mark 99% of my functions with 
 nogc.

I just seems very annoying to add  nogc to every function.

For people like me it seems that it could be a nice addition to 
also allow  nogc for structs like

 nocgc struct Foo{..}

or blocks

 nogc{
    void foo(){}
    void foo1(){}
}

or even modules

 nogc module Foo

What do you think?
Feb 15 2016
parent reply WebFreak001 <janju007 web.de> writes:
On Tuesday, 16 February 2016 at 02:42:06 UTC, maik klein wrote:
 I just seems very annoying to add  nogc to every function.
you can mark everything as nogc with // gc functions here nogc: // nogc functions here void foo() {}
Feb 15 2016
parent reply maik klein <maikklein googlemail.com> writes:
On Tuesday, 16 February 2016 at 02:47:38 UTC, WebFreak001 wrote:
 On Tuesday, 16 February 2016 at 02:42:06 UTC, maik klein wrote:
 I just seems very annoying to add  nogc to every function.
you can mark everything as nogc with // gc functions here nogc: // nogc functions here void foo() {}
Thanks, this should probably added to https://dlang.org/spec/attribute.html#nogc I just realized that I can't even use nogc because pretty much nothing in phobos uses nogc
Feb 15 2016
next sibling parent reply Era Scarecrow <rtcvb32 yahoo.com> writes:
On Tuesday, 16 February 2016 at 03:13:48 UTC, maik klein wrote:
 I just realized that I can't even use  nogc because pretty much 
 nothing in phobos uses  nogc
Or it hasn't been tagged nogc or based on templates they can't be preemptively marked it. I'd think most ranges could be nogc; And recently with some of the toString's being rewritten to use ranges instead of allocating memory would be nogc as well. Many algorithms are probably be nogc too.
Feb 15 2016
parent rsw0x <anonymous anonymous.com> writes:
On Tuesday, 16 February 2016 at 03:41:12 UTC, Era Scarecrow wrote:
 On Tuesday, 16 February 2016 at 03:13:48 UTC, maik klein wrote:
 I just realized that I can't even use  nogc because pretty 
 much nothing in phobos uses  nogc
Or it hasn't been tagged nogc or based on templates they can't be preemptively marked it. I'd think most ranges could be nogc; And recently with some of the toString's being rewritten to use ranges instead of allocating memory would be nogc as well. Many algorithms are probably be nogc too.
templated constructs aren't tagged nogc because it's inferred, tagging them nogc would impose restrictions on the end user
Feb 15 2016
prev sibling next sibling parent jmh530 <john.michael.hall gmail.com> writes:
On Tuesday, 16 February 2016 at 03:13:48 UTC, maik klein wrote:
 Thanks, this should probably added to 
 https://dlang.org/spec/attribute.html#nogc
It's actually in there, it's just easy to miss. It's the box with the text after "Attributes are a way to modify one or more declarations. The general forms are: "
Feb 15 2016
prev sibling parent John Colvin <john.loughran.colvin gmail.com> writes:
On Tuesday, 16 February 2016 at 03:13:48 UTC, maik klein wrote:
 On Tuesday, 16 February 2016 at 02:47:38 UTC, WebFreak001 wrote:
 On Tuesday, 16 February 2016 at 02:42:06 UTC, maik klein wrote:
 I just seems very annoying to add  nogc to every function.
you can mark everything as nogc with // gc functions here nogc: // nogc functions here void foo() {}
Thanks, this should probably added to https://dlang.org/spec/attribute.html#nogc I just realized that I can't even use nogc because pretty much nothing in phobos uses nogc
You probably can, remember that templates have their attributes inferred.
Feb 16 2016