digitalmars.D - Unfortunately delete is a keyword
- Rory Mcguire (43/43) Jul 29 2010 Inspired by the recent thread "Proposal for dual memory management" I
- Kagamin (2/4) Jul 29 2010 You can also try to implement switch, for and while statements in a simi...
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (9/15) Jul 29 2010 ilar way. That's a whole bunch of keywords.
- Kagamin (2/4) Jul 29 2010 every language designer's dream :3
- Rory Mcguire (5/12) Jul 29 2010 hmm, there was a benchmark here somewhere where somone (bearofile?) comp...
Inspired by the recent thread "Proposal for dual memory management" I
wondered how long it would take to change scoped into heaped.
Now I wish I could call the free method delete.
I didn't put the full test source here because I had to copy some stuff from
phobos svn.
Please let me know what you think, is this already done?
-Rory
code:
system auto heaped(alias T,Args...)(Args args) {
struct HeapAlloc {
private void *buf;
T cpayload() {
return cast(T)(cast(byte[]*)buf);
}
alias cpayload this;
void free() {
destroy(cpayload);// not in 2.046
// not sure what this does!!!
if ((cast(void**) cpayload)[1]) {
_d_monitordelete(cpayload, true);
}
.free(buf);
}
}
void* mem = malloc(__traits(classInstanceSize, T));
if (!mem)
throw new Exception("no mem");
emplace!T(cast(void[])mem[0..__traits(classInstanceSize,T)],args);
HeapAlloc ret;
ret.buf = mem;
return ret;
}
Usage:
auto a = heaped!A;
auto b = heaped!A(10);
assert(a.i==3);
assert(a.getI()==3);
assert(b.i==10);
assert(b.getI()==10);
a.free();
b.free();
Jul 29 2010
Rory Mcguire Wrote:Inspired by the recent thread "Proposal for dual memory management" I wondered how long it would take to change scoped into heaped.You can also try to implement switch, for and while statements in a similar way. That's a whole bunch of keywords.
Jul 29 2010
Kagamin wrote:Rory Mcguire Wrote: =20Inspired by the recent thread "Proposal for dual memory management" I =ilar way. That's a whole bunch of keywords. Then you get scheme (or felix) where almost all the language constructs are actually part of the std library... Jerome --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.frwondered how long it would take to change scoped into heaped.=20 You can also try to implement switch, for and while statements in a sim=
Jul 29 2010
Jérôme M. Berger Wrote:Then you get scheme (or felix) where almost all the language constructs are actually part of the std library...every language designer's dream :3
Jul 29 2010
Kagamin wrote:Rory Mcguire Wrote:hmm, there was a benchmark here somewhere where somone (bearofile?) compared if and if else performance to a switch statements performance and if did get better performance for some things. :DInspired by the recent thread "Proposal for dual memory management" I wondered how long it would take to change scoped into heaped.You can also try to implement switch, for and while statements in a similar way. That's a whole bunch of keywords.
Jul 29 2010









Kagamin <spam here.lot> 