template codegeneration issues
- From: "Serge Skorokhodov (216716244)" <suralis-s@xxxxxxxxxx>
- Date: Fri, 04 Nov 2005 13:26:25 +0300
Hi,
I just seeking advice.
Some background information first because I've run into issues
that seems pretty obscure to me:( Quick search through KB yields
next to nothing. Simplified samples work OK as well, the problems
appear in rather bulky code:(
I'm trying to implement some signal processing algorithm using
templates with integral template arguments (sampling rate, window
and delay sizes etc.) in VC 7.1. The template classes contain
static and non-static const members that depend on template
arguments. Some of these classes are used as template arguments
in higher level classes.
The problems:
1. The values of non-static const members is changed in run-time.
It can be easily observed in the debbuger and it looks like
certain member variables and const members are placed at the same
memory locations. A simplified illustration may be like this:
template < int sr >
myContainedClass
{
public:
myContainedClass() { /* some code */ }
void reset_internals() { /* some code */ }
private
static const int buf_sz = int(sr*80.0/1000.0 + 0.5);
int buffer[buf_sz];
};
template < class contained_class_t, int sr >
class myClass
{
public:
myClass() : contained_class(sr), some_const(0.5)
{
// some_const == 0.5 here
contained_class.reset_internals();
// some_const == some other value here
}
private:
contained_class_t contained_class;
const double some_const;
};
2. The members of different variables of the abovementioned
template classes seem to similarly "overlap" in memory:(
SomeClass var1( /*some initialization args*/);
myClass<500> var2;
// here some var1 data is corrupted by the code of var2 ctor:(
Adding additional "dummy" data members may eliminate the errors.
Is it a known problem? Can somebody make a suggestion how to
avoid it? Maybe a workaround? I understand that using other
(simpler:) coding style will help. But I really enjoy both
flexibility and performance that C++ templates promise;)
Sorry for not messy posting but I really failed to demonstrate a
problem in a simple and short code snippet:(
TIA
--
Serge
.
- Follow-Ups:
- Re: template codegeneration issues
- From: Tom Widmer [VC++ MVP]
- Re: template codegeneration issues
- Prev by Date: Re: marshaling the System::Guid structure
- Next by Date: Re: template codegeneration issues
- Previous by thread: Re: Porting .NET Encryption to Win32 or ATL
- Next by thread: Re: template codegeneration issues
- Index(es):
Relevant Pages
|