New answers tagged

3

Use member initializer lists in constructors where possible Using member initializer lists can be more optimal and avoid issues when an error is thrown in a constructor. Use it where possible. For example: FIR(const std::vector<T> &v): coeff(v), taps(coeff.size()), order(coeff.size()) {} Make sure you initialize the members in the same order as ...


3

class FIR has nothing private. Should it be struct? The line std::list< T > taps; // Array of is are shifting each tick is somewhat contradictory. It taps a list or an array? I don't see how order is used. Does it need to be a class member at all? operator()(T x) is very confusing. I would argue that it shall not be an operator at all; if you ...


1

for ( c =coeff.begin(), t =taps.begin(); c!=coeff.end(), t !=taps.end(); ++c , ++t ){ psum += (*c) * (*t); } I'm guessing the comma in the for loop condition should be an &&. It might be cleaner to use an index in this loop instead (especially if the two arrays are always the same ...


2

In parallel programming, it's often useful to try to minimize the degree to which the threads work with the same data. In this case, you have all the threads doing updates to E almost constantly throughout execution. To minimize collisions, I'd allocate a separate instance of E for each iteration of the loop you decide to execute in parallel, then after you'...


1

So you need to parallelize it and wonder where you should write #pragma omp parallel for There are many permutations of this that might be more effective, see manual for more, but try to place it just before the first loop.


5

Avoid using namespace std; If you are coding professionally you probably should get out of the habit of using the using namespace std; statement. The code will more clearly define where cout and other identifiers are coming from (std::cin, std::cout). As you start using namespaces in your code it is better to identify where each function comes from because ...


2

WAV_HEADER: bool read(std::istream& s) { if (s.good()) { s.seekg(0u); s.read(&m_0_headerChunkID[0], 4); s.read((char*)&m_4_chunkSize, 4); s.read(&m_8_format[0], 4); s.read(&m_12_subchunk1ID[0], 4); s.read((char*)&m_16_subchunk1Size, 4); s.read((char*)&m_20_audioFormat,...


6

Ensure correct order of constructor member initializers My compiler warns me that in the constructors of Waveread, m_cachePos and m_opened are initialized in the wrong order. The order of the constructor initializer list should match the order in which the member variables are declared, otherwise they might be initialized in a different order than you ...


0

s.read(&m_0_headerChunkID[0], 4); s.read((char*)&m_4_chunkSize, 4); s.read(&m_8_format[0], 4); s.read(&m_12_subchunk1ID[0], 4); s.read((char*)&m_16_subchunk1Size, 4); s.read((char*)&m_20_audioFormat, 2); s.read((char*)&m_22_numChannels, 2); s.read((...


1

Here is my code review, I see 2 things: Here we can read: std::max_align_t is usually synonymous with the largest scalar type, which is long double on most platforms, and its alignment requirement is either 8 or 16. So the alignment of storage is wrong I think, it should probably be made explicit: alignas (std::max_align_t) Storage storage; Also, you ask ...


3

Avoid casting time too much A lot of code is spent on converting time to integers. Avoid casting too early; store time as much as possible as std::chrono types. In fact, intead of storing how much tokens there are in the bucket, you could instead store how much time there is in the bucket. Then only in areTokensAvailable() do you need to cast from the amount ...


2

If you are programming c++ you should avoid functions like fprintf(from C), you should use std::cout that is the one on the standard library of c++


2

Remove class IEventHandler Unless you plan to have multiple classes that inherit IEventHandler, there is no point in declaring an IEventHandler and having EventHandler inherit from it. Avoid duplicating functionality In the constructor that takes a Message *, you duplicate code from OnMessage() and startEventHandlerThread(). It is always best to avoid code ...


2

Overview I started the code review but stopped half way through. This is all wrong. A reactor should hold a thread pool (or a single thread to do the work). When an event is triggered a thread is released from the pool and simply calls the OnMessage() method of all appropriately registered handlers. You are confusing the event handler pattern and the reactor ...


Top 50 recent answers are included