On one hand, the author says that instanciating the singleton and storing it is not safe because there is no synchronization, but on the other hand he says that null check before is safe because the mutex introduces synchronization.
My understanding would be that the mutex protects this whole section and that the atomic is not necessary at all in this case.
I guess Matsumoto should have charged for Ruby. I'm sure Mike Perham and Derek Kraan would have been glad to pay for that and that the Ruby community would be in a strong and healthy shape.
This just describes the structure. Structure without intent is useless.
Comments and out of code documentation both have the same problems :
- Blindspots
- Rot
That is not to say they are useless, but they are rarely if ever sufficient.
In the end, the most complete and trustworthy source of truth for the code is the code itself.
Help others by having your code describe your intent. Using appropriate variable name and using appropriate types _help_ to keep displayed intent in sync with reality.
Another point to consider is that for the same intent the structure may need to change, to evolve. Proper typing can insulate the code from those changes.
N.B. I'm writing my comments as I am reading your code. Please, don't take offense from my criticism, it is meant to be constructive, albeit concise.
/*
* @brief Retrieve a continuous block of
* valid buffered data.
* @param num_reads_requested How many reads are required.
* @param skip Whether to increment the read position
* automatically, (false for manual skip
* control)
* @return A block of items containing the maximum
* number the buffer can provide at this time.
/
Block<T> Read(unsigned int num_reads_requested)
Where is skip?
> if (buffer_full)
> {
> /
> * Tried to append a value while the buffer is full.
> /
> overrun_flag = true;
> }
> else
> {
> /
> * Buffer isn't full yet, write to the curr write position
> * and increment it by 1.
> /
> overrun_flag = false;
> data[write_position] = value;
> write_position = (write_position + 1U) % LENGTH;
> }
You don't write in the case of an "overrun". Isn't that one of the most interesting property of a ringbuffer? It seems that your implementation is specific to your use case (buffering to sd cards?). I don't think your _current_ implementation is apropriate for a _general_ purpose ring buffer mostly because of api concerns. It may be interesting to emphasis this part in your doc.
> reads_to_end = LENGTH - read_position;
> req_surpasses_buffer_end = num_reads_requested > reads_to_end;
>
> if (req_surpasses_buffer_end)
> {
> /
> * If the block requested exceeds the buffer end. Then
> * return a block that reaches the end and no more.
> /
> block.SetStart(&(data[read_position]));
> block.SetLength(reads_to_end);
> }
> else
> {
> /
> * If the block requested does not exceed 0
> * then return a block that reaches the number of reads required.
> */
> block.SetStart(&(data[read_position]));
> block.SetLength(num_reads_requested);
> }
Yeah, you're right. The USA right now is in a good state on the matter of social policy, and I don't see any way it could be improved.
Especially if it takes taxing the "rich" more. Imagine the chaos that would ensue...
In fact, I'd go as far as to say that the current problem in the USA is that market is not free enough. Trump should definitely lower taxes on higher incomes and cut services. This can only push innovation! Think about how quick this whole "crisis" would be solved if it weren't for government intervention!
I used to work for a car rental company. Actually, it was an insurance company that rented car. Cause 80% of their profits were on the insurance. The car rental part was just to bring more people to insurance part.
It's really that speaking french in a predominantly french region shouldn't stop you from getting a job you have every competencies to achieve. That's why the law can go into absurd territory(e.g. having only english equipment cannot be a valid reason to refuse employment to a francophone).
But then again, most of the law only applies once your business reach a certain number of employees(30 I think)
I think his point is that when comparing running SalesForce on the cloud for every users SalesForce has, vs running SalesForce locally for your users, there will a lot less challenge to keep it running locally than on the cloud.
That's the part I missed : the first null check can be skipped if the memory is allocated but the constructor hasn't been executed.