Topic: A temporary question
Author: janosy@lte.e-technik.uni-erlangen.de (Zoltan Janosy)
Date: Mon, 12 Apr 1993 16:05:36 GMT Raw View
Hi:
I'm trying to implement a signal processing library in C++. I would like to
define the basic arithmetical operations on signals. My idea was that I
make the operations return a placeholder for the operation and the operands,
and compute the operation only when assigning it to a signal. In that way I
don't need temporary memory for the intermediate results.
The idea was not bad, but in the case of nested operations (e.g. where one
of the operands is an operation too) it didn't work. First I thought it was a
bug in g++, because the same program worked with Borland C++ 3.1. But
after some line-by-line debugging sessions I realized, that the problem is,
my temporaries are destroyed before I evaluated the operation stored in them.
Unfortunately I learned from ARM, that this behaviour is legal.
If anyone faced the problem already (I'm sure about that :-), and found a
relatively simple and working solution, please do not hesitate to tell it to me.
Thank you,
Zoltan Janosy, postgraduate fellow
P.S. Meanwhile I came up with two solutions, but I don't like them. One is to allocate the
temporaries on the heap, the other is to use a pool of preallocated operation objects.
I also learned, that there is a debate going on in the C++ standardization commitee
about this subject, and probably this year the rule of destroying the temporaries will
change (to my benefit). But until then (and when will g++ have it ???) ... If someone
has better ideas, they are welcomed.
Universitaet Erlangen-Nuernberg Technical University of Budapest
Lehrstuhl fuer Technische Elektronik Department of Telecommunications
Cauerstr. 9. Sztoczek u. 2.
W-8520 Erlangen, Germany H-1111 Budapest, Hungary
janosy@lte.e-technik.uni-erlangen.de h3083jan@ella.hu
I made this letter longer than usual because I lack the time to make it shorter.
-- Pascal
---
Zoltan Janosy, postgraduate fellow
Universitaet Erlangen-Nuernberg Technical University of Budapest
Lehrstuhl fuer Technische Elektronik Department of Telecommunications
Cauerstr. 9. Sztoczek u. 2.
W-8520 Erlangen, Germany H-1111 Budapest, Hungary
janosy@lte.e-technik.uni-erlangen.de h3083jan@ella.hu
I made this letter longer than usual because I lack the time to make it shorter.
-- Pascal