* ma740988:
Assume I have a vendor file called ' vendor.h'. Within the file
there's two methods memalign and cforward. It is my understanding that
the memalign function is a wrapper around malloc. cforward is just a
vendor function for doing forward FFT's. At issue CSL_COMPLEX is
'cumbersome' to work with. As a result I created a wrapper. So now -
given the pseudo code.
#include <iostream>
#include <complex>
#include <vector>
// in vendor file - vendor.h
struct CSL_COMPLEX {
float r;
float i ;
};
void *memalign(size_t blocksize, size_t bytes)
{
return ( malloc ( blocksize * bytes ) ) ; // not sure if I have this
right but .. for test purposes
}
void cforward (
CSL_COMPLEX* ptr_input,
CSL_COMPLEX* ptr_ouput,
int num_sample
)
{}
// end vendor.h
Are you sure the cforward function has special alignment requirements
above those provided by C++ new? If not, just use a
std::vector<CSL_COMPLEXin your client code. Or rather, two of them.
Client code might look like this (off the cuff, not test-compiled):
typedef CSL_COMPLEX CslComplex; // Get rid of uppercase, principle.
typedef std::vector<CslComplexCslValues;
void transform( CslValues const& data, CslValues& result )
{
if( data.size() == 0 ) { return; }
CslValues resultBuffer( data.size() );
cforward(
const_cast<CslComplex*>( &data[0] ),
&resultBuffer[0],
static_cast<int>( data.size() )
);
// Possible error checking here, I don't see that provided? Then:
std::swap( resultBuffer, result ); // Constant time.
}
// Wrapper for notational ease, relying on modern compiler with RVO.
// If measurements show unacceptable time used on copying, one might
// need to rewrite client code to use 'transform' above directly.'
// But that would be a premature optimization without measurements.
inline CslValues transformed( CslValues const& data )
{
CslValues result;
transform( data, result );
return result;
}
struct MakeCslComplex: CslComplex
{
MakeCslComplex( CslComplex const& v ) { r = v.i; i = v.i; }
MakeCslComplex( float re, float im ) { r = re; i = im }
// Etc., eg. conversion from std::complex<double>
};
int main()
{
CslValues data;
data.push_back( MakeCslComplex( 1.0, 2.0 ) );
data.push_back( MakeCslComplex( 3.0, 4.0 ) );
// etc.
CslValues result = transformed( data );
}
Hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?