www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - gc heap

reply Sam S E <asdf mailinator.com> writes:
What is allocated in the gc heap? Just classes? Dynamic/associative arrays?
Structs? Only things allocated with new? Do built-in types and structs get
deallocated at the end of scope like in C?
Nov 23 2008
next sibling parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Sun, Nov 23, 2008 at 5:02 PM, Sam S E <asdf mailinator.com> wrote:
 What is allocated in the gc heap? Just classes? Dynamic/associative arrays?
Structs? Only things allocated with new? Do built-in types and structs get
deallocated at the end of scope like in C?

Everything that is a reference type (classes, dynamic arrays, AAs) is allocated on the heap. Everything that is a value type (basic types, fixed-size arrays, structs) are allocated on the stack and are deallocated when the scope is left. scope references to classes will delete the class they refer to when the scope is left. As a special case, a declaration of the form "scope x = new ClassType()" will actually allocate the class instance on the stack instead of on the heap.
Nov 23 2008
parent reply Sam S E <asdf mailinator.com> writes:
Jarrett Billingsley Wrote:

 On Sun, Nov 23, 2008 at 5:02 PM, Sam S E <asdf mailinator.com> wrote:
 What is allocated in the gc heap? Just classes? Dynamic/associative arrays?
Structs? Only things allocated with new? Do built-in types and structs get
deallocated at the end of scope like in C?

Everything that is a reference type (classes, dynamic arrays, AAs) is allocated on the heap. Everything that is a value type (basic types, fixed-size arrays, structs) are allocated on the stack and are deallocated when the scope is left. scope references to classes will delete the class they refer to when the scope is left. As a special case, a declaration of the form "scope x = new ClassType()" will actually allocate the class instance on the stack instead of on the heap.

Thank you; thanks to you I now have a basic understanding of all the features of D. Now if only Walter could implement all of them :) --Sam
Nov 23 2008
parent reply Sam S E <asdf mailinator.com> writes:
Jarrett Billingsley Wrote:

 On Sun, Nov 23, 2008 at 5:35 PM, Sam S E <asdf mailinator.com> wrote:
 Thank you; thanks to you I now have a basic understanding of all the features
of D. Now if only Walter could implement all of them :)
 --Sam

What's that supposed to mean?

There are many useful and interesting features that are planned but unimplemented.
Nov 23 2008
parent reply Sam S E <asdf mailinator.com> writes:
Jarrett Billingsley Wrote:

 On Sun, Nov 23, 2008 at 6:48 PM, Sam S E <asdf mailinator.com> wrote:
 Jarrett Billingsley Wrote:

 On Sun, Nov 23, 2008 at 5:35 PM, Sam S E <asdf mailinator.com> wrote:
 Thank you; thanks to you I now have a basic understanding of all the features
of D. Now if only Walter could implement all of them :)
 --Sam

What's that supposed to mean?

There are many useful and interesting features that are planned but unimplemented.

...like what?

See http://s3.amazonaws.com/dconf2007/WalterAndrei.pdf. There are some amazing feature listed there. I can't think of anything else I'd like to see implemented (except for automatic type inference of substructs in struct literals). I don't know how to explain those, so I'll give an example: struct Foo { int a; int b; } struct Bar { Foo f; real asdf; } auto def = Bar(Foo(1, 42), 13.7); //current Bar def = {{1, 42}, 13.7}; //C-style //downside: only possible if you initialize //when you declare auto def = Bar({1, 42}, 13.7); //Bar for clarity, Foo obvious //simpler, especially with many nested structs I've gotten pretty far off topic; this probably deserves it's own thread by now. --Sam
Nov 23 2008
parent reply Sam S E <asdf mailinator.com> writes:
Jarrett Billingsley Wrote:

 On Sun, Nov 23, 2008 at 10:59 PM, Sam S E <asdf mailinator.com> wrote:
 See http://s3.amazonaws.com/dconf2007/WalterAndrei.pdf.
 There are some amazing feature listed there. I can't think of anything else
I'd like to see implemented (except for automatic type inference of substructs
in struct literals).

Ah, OK. Yeah, I wonder if a good number of those features will make it into D anytime soon. Walter already said macros will be put off until D3, which were one of the major things I was looking forward to for D2.. in the mean time, a number of other ideas have come up and have taken precedence over many things mentioned in the slides. Some are already implemented, though.
 I don't know how to explain those, so I'll give an example:

 struct Foo
 {
    int a;
    int b;
 }

 struct Bar
 {
    Foo f;
    real asdf;
 }

 auto def = Bar(Foo(1, 42), 13.7);  //current
 Bar def = {{1, 42}, 13.7};            //C-style
                                                 //downside: only possible if
you initialize
                                                 //when you declare
 auto def = Bar({1, 42}, 13.7);      //Bar for clarity, Foo obvious
                                        //simpler, especially with many nested
structs

Better struct literals would be nice.

Better in what way? Do you like my syntax or do you have a better one?
Nov 23 2008
parent Sam S E <asdf mailinator.com> writes:
Jarrett Billingsley Wrote:

 On Mon, Nov 24, 2008 at 12:51 AM, Sam S E <asdf mailinator.com> wrote:
 Better in what way? Do you like my syntax or do you have a better one?

Oh, I was agreeing with you, as well as implying that struct literals in general could be improved.

You're right, struct literals need to be updated, but I don't think it's possible to make them any shorter than my suggestion, except maybe a bracket or two; you need to at least specify the type of the whole thing. --Sam
Nov 24 2008
prev sibling next sibling parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Sun, Nov 23, 2008 at 5:35 PM, Sam S E <asdf mailinator.com> wrote:
 Thank you; thanks to you I now have a basic understanding of all the features
of D. Now if only Walter could implement all of them :)
 --Sam

What's that supposed to mean?
Nov 23 2008
prev sibling next sibling parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Sun, Nov 23, 2008 at 6:48 PM, Sam S E <asdf mailinator.com> wrote:
 Jarrett Billingsley Wrote:

 On Sun, Nov 23, 2008 at 5:35 PM, Sam S E <asdf mailinator.com> wrote:
 Thank you; thanks to you I now have a basic understanding of all the features
of D. Now if only Walter could implement all of them :)
 --Sam

What's that supposed to mean?

There are many useful and interesting features that are planned but unimplemented.

...like what?
Nov 23 2008
prev sibling next sibling parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Sun, Nov 23, 2008 at 10:59 PM, Sam S E <asdf mailinator.com> wrote:
 See http://s3.amazonaws.com/dconf2007/WalterAndrei.pdf.
 There are some amazing feature listed there. I can't think of anything else
I'd like to see implemented (except for automatic type inference of substructs
in struct literals).

Ah, OK. Yeah, I wonder if a good number of those features will make it into D anytime soon. Walter already said macros will be put off until D3, which were one of the major things I was looking forward to for D2.. in the mean time, a number of other ideas have come up and have taken precedence over many things mentioned in the slides. Some are already implemented, though.
 I don't know how to explain those, so I'll give an example:

 struct Foo
 {
    int a;
    int b;
 }

 struct Bar
 {
    Foo f;
    real asdf;
 }

 auto def = Bar(Foo(1, 42), 13.7);  //current
 Bar def = {{1, 42}, 13.7};            //C-style
                                                 //downside: only possible if
you initialize
                                                 //when you declare
 auto def = Bar({1, 42}, 13.7);      //Bar for clarity, Foo obvious
                                        //simpler, especially with many nested
structs

Better struct literals would be nice.
Nov 23 2008
prev sibling parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Mon, Nov 24, 2008 at 12:51 AM, Sam S E <asdf mailinator.com> wrote:
 Better in what way? Do you like my syntax or do you have a better one?

Oh, I was agreeing with you, as well as implying that struct literals in general could be improved.
Nov 23 2008