Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
May 07, 2004 Auto classes are limiting | ||||
---|---|---|---|---|
| ||||
If a class is defined as auto, I am unable to keep an instance alive longer than its scope. I would like there to be a way to specify non-auto. Most of the time I want to immediately destruct a memory mapped file, but sometime I might want to keep it around for awhile; I'd have to rewrite or modify the code! -- Christopher E. Miller |
May 07, 2004 Re: Auto classes are limiting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | Vathix wrote:
> If a class is defined as auto, I am unable to keep an instance alive longer than its scope. I would like there to be a way to specify non-auto. Most of the time I want to immediately destruct a memory mapped file, but sometime I might want to keep it around for awhile; I'd have to rewrite or modify the code!
You're right, they are. On the bright side, you don't have to use auto that way. Just write the class itself as non-auto, and use auto instances as needed.
This is perfectly legal:
class A {
...
}
A foo() {
auto A a = new A();
A b = new A();
// a should be cleaned up when the function is done, b will not,
// as it was not declared as auto
return b;
}
-- andy
|
May 07, 2004 Re: Auto classes are limiting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | In article <c7ggfk$v9r$1@digitaldaemon.com>, andy@ikagames.com says... >This is perfectly legal: > > class A { > ... > } > > A foo() { > auto A a = new A(); > A b = new A(); > > // a should be cleaned up when the function is done, b will not, > // as it was not declared as auto > return b; > } > > -- andy Right, but I mean when using someone else's code; like std.mmfile.MmFile is auto, so I'm stuck with an auto class, or I have to use my own code. (By the way, when I click std.mmfile at the top of phobos.html, it doesn't scroll down to it because the <A> tag is incorrect.) -- Christopher E. Miller |
May 10, 2004 Re: Auto classes are limiting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | Vathix wrote: > In article <c7ggfk$v9r$1@digitaldaemon.com>, andy@ikagames.com says... > >>This is perfectly legal: >> >> class A { >> ... >> } >> >> A foo() { >> auto A a = new A(); >> A b = new A(); >> >> // a should be cleaned up when the function is done, b will not, >> // as it was not declared as auto >> return b; >> } >> >> -- andy > > > Right, but I mean when using someone else's code; like std.mmfile.MmFile is auto, so I'm stuck with an auto class, or I have to use my own code. (By the way, when I click std.mmfile at the top of phobos.html, it doesn't scroll down to it because the <A> tag is incorrect.) I don't see why that particular class has to be auto either. Why should an mmfile have to have function-local scope whether the programmer likes it or not? I suppose a possible workaround is to wrap the mmfile in a thread.... Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
May 11, 2004 Re: Auto classes are limiting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | "Stewart Gordon" <smjg_1998@yahoo.com> wrote in message news:c7o59r$2u8c$1@digitaldaemon.com... > Vathix wrote: > > > In article <c7ggfk$v9r$1@digitaldaemon.com>, andy@ikagames.com says... > > > >>This is perfectly legal: > >> > >> class A { > >> ... > >> } > >> > >> A foo() { > >> auto A a = new A(); > >> A b = new A(); > >> > >> // a should be cleaned up when the function is done, b will not, > >> // as it was not declared as auto > >> return b; > >> } > >> > >> -- andy > > > > > > Right, but I mean when using someone else's code; like std.mmfile.MmFile is auto, so I'm stuck with an auto class, or I have to use my own code. (By the way, when I click std.mmfile at the top of phobos.html, it doesn't scroll down > > to it because the <A> tag is incorrect.) > > I don't see why that particular class has to be auto either. Why should an mmfile have to have function-local scope whether the programmer likes it or not? That was the way Walter wanted it, and it seemed ok to me at the time. I concur that it should probably not be. Perhaps one of you could post is as a bug on the bugs NG, and we'll fix it for next time? > > I suppose a possible workaround is to wrap the mmfile in a thread.... > > Stewart. > > -- > My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
Copyright © 1999-2021 by the D Language Foundation