Sponsored Link •
|
Summary
In languages like C++, functions return temporary stack allocated values which can be very inefficient. I am using a technique on Heron which I call transfer semantics to provide a work-around.
Advertisement
|
In Heron and C++ functions return stack allocated temporary values. This means that code like the following ends up being suboptimal:
class MyBigClass { public { // the overloaded = operator _eq(self x) { delete(m); m = new OtherBigClass(x.m); } } fields { OtherBigClass^ m; // owner pointer } } f() : MyBigClass { ... } g() { MyBigClass x; x = f(); // inefficient }In Heron return values from a function are a special kind of template called a temporary<T>. This means I can instead write an optimized assign for when assigning from function results which would like the following:
// = operator, overloaded for temporaries _eq(temporary<self> x) { delete(m); transfer(m, x.m); }The temporary<T> type will behave exactly like T, it simply identifies the value as a temporary so the programmer can write more intelligent code. I call this transfer semantics, but I might be misuing the term. Any thoughts on the approach and terminology?
Have an opinion? Readers have already posted 12 comments about this weblog entry. Why not add yours?
If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.
Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com. |
Sponsored Links
|