Monday, 23 July 2018

Microsoft's Noexcept Code Throws Exceptions

I've not dug into this one fully yet, I'm mid-stride on what's going on, however the stack has unspooled me to this location having thrown a read access violation...


But can you see the problem here?  I'm in Microsoft's xstring, as far as I'm concerned this is from my using std::string or std::ostringstream, the function is decorated "noexcept" yet its throwing an exception!


I find this mind bendingly annoying, not least as under GCC & clan on Linux it runs perfectly fine!

So, this is "Unhandled exception thrown: read access violation" in xstring _Equal which is decorated noexcept... Time to format c: and never use Windows I think.

Saturday, 21 July 2018

C++ : Coding Standards by Example #1 (with Boost Beast)

Today I've spent sometime doing a little different video, rather than just play about in code, whilst I played about I made a video of the time I had... Here is it...


We cover:


  • C++
  • Coding Standards
  • Structured Programming
  • Functional Programming
  • Encapsulation
  • Object Orientated Programming
  • Building the Boost Libraries (1.67.0)
  • Visual Studio 2017
  • Static Linking

And generally spend time seeing how I turn gobble-de-gook code into something usable and maintainable against my own Coding Standards.

Get the code yourself here: https://github.com/Xelous/boostBeast

Friday, 20 July 2018

That Moment...

That moment you get half an hour into watching Brad Pitt in War Machine and the wife suddenly asks....

"Do you know him?"

"Who?"

"The actor!"

"Which actor?"

"Him with the grey hair?"

"The General?"

"Yes"

"Brad Pitt"

"Fuck off, that's not Brad Pitt"

I gave up.

Thursday, 19 July 2018

C++ : Copy Constructor versus Ignorance

I've spent a bit of time reviewing someone else's code recently and I've come to an impasse with them, so they have a lot of code which will take some standard container, and the code doesn't just initialise the local copy from the passed in reference... No it'll iterate over the list of elements adding them to the class version.

I have picked fault with this, it's not RAII, it looks ugly and if you're threading you can create your class instance and the member is empty or in a partially filled state before the loop within the constructor is finished... I highlight this in red below...

My solution?  Just initialise the member from the reference - see the green highlight in the code below.

My results from the timing below?



These times are "microseconds" so tiny... But with just constructing from the existing reference we always get a lower time, quicker code...


Running this test 30,000 times, trying it in different orders and with maps of upto 1000 elements I had a rough average increase of 60% speed by using the copy constructor of std::map rather than reallocating new memory for each pre-existing element.

I wanted therefore to understand the reasoning behind the original code, was there some reason to perform a clone (alloc and assign new instance) operation for each pair in the map being passed in?  Looking at the code there was no apparent reason, so I spoke to the developer, asking why they had performed the construction in this manner... Their reply...

"That's how you initialise a container"

You can load up a container in this manner, but you already have the contents of the map, you're just copying it... "Why don't you use the copy constructor?"... I asked...

"I didn't write one"

Hmm, "You don't, the compiler generates it for you, std::map has its own copy constructor".  Use the copy constructor folks, trust me.


#include <map>
#include <chrono>
#include <string>
#include <iostream>


using Mapping = std::map<int, int>;

class A
{
private:
Mapping m_TheMapping;

public:

A() = delete;
A(const A&) = delete;
void operator=(const A&) = delete;

A(const Mapping& p_Mapping)
:
m_TheMapping(p_Mapping)
{
}

A(const Mapping& p_Mapping, const bool& p_Other)
:
m_TheMapping()
{
for (auto i : p_Mapping)
{
m_TheMapping.emplace(i);
}
}

inline Mapping& Mapping()
{
return m_TheMapping;
}
};


int main()
{
Mapping l_m
{
{ 0, 0 },
{ 1, 1 },
{ 2, 2 },
{ 3, 3 }
};

auto l_time(std::chrono::high_resolution_clock::now());
// Copy Construction
A l_map(l_m);
auto l_timeB(std::chrono::high_resolution_clock::now());

auto l_Dur(l_timeB - l_time);
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(l_Dur).count() << std::endl;


auto l_time2(std::chrono::high_resolution_clock::now());
// Clone Construction
A l_map2(l_m, true);
auto l_time2B(std::chrono::high_resolution_clock::now());

auto l_DurB(l_time2B - l_time2);
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(l_DurB).count() << std::endl;
}

Tuesday, 17 July 2018

Preach at the Bar?

Oh its been a long hard fortnight, delivery of project at work and the World Cup took up most of the last week, my cars (yes both of them) have cost me a total of £1,100 so far and one of them is still broke... Hence I'm broke.

However, I've been working on a project this very evening and whilst doing so I spotted something rather odd.

You might have thought the Preacher was busy sorting out the festivities at PreachCon, however, I think he's been moonlighting on us... No he's not been playing a game other than Warcraft... Oh no... He's literally IN another game... Take a look...


From NeebsGaming's video of Drunken Bar Fight... Uncanny Valley or what mate!

That's the Preach!  No-one knows where Ghosty is though...

Sunday, 8 July 2018

Friday, 6 July 2018

My Three Lions 2018

Being English, specifically an avid supporter of English Football this week is extremely hard to bear, the hope, the wish, the fear the turbid mix on the street, wafting on the radio airwaves and in nearly every news report.

I love English football, the agony, the pleasure, that moment the wife storms out the room declaring "I'm stopping watching this" only to see here peeping around the door-frame thirty seconds later.

We love you England, we do.

And I find a tear in my eye whenever I think back to that warm summer of '96 as here in Nottingham we saw the Turkish team play at the City Ground and the hurt that followed.


I stand up to be counted.  I am English.  We are United.  We will play.  I hope they can win.

But whatever the weekend brings, we still have our Lions, three of them, proud and loud.

Hear Us Roar.

Thursday, 5 July 2018

Trade... Post Brexit....

Lets get serious, when the UK leaves the EU there's going to be huge ramifications to our trade... But I think there's a solution...

TRUMP... Oi, Trump.. We want a free-trade agreement with Chichester...

Our reciprocation?.... Well we'll consider giving you this....


Monday, 2 July 2018

Is It Filmable? Ready Player One

Quite controversially, amongst the fans of the book, I really liked the film called Ready Player One...


See what I did there?  I separated the book from the film... They have the same name in the sense that we call a Guinea Pig a pig... But they're not pigs and despite borrowing a few parts this film is not of the much better book.

Why the divergence?  Well, simply put the appeal would have been too niche, the geek chique of even knowing about RP1 is far below the radar scatter detection level of a Hollywood film executive or producer squad, and sadly gone are the games of rock or pop stars funding a film just "so they can see it" (*cough* shout out to George Harrison there).

The book therefore does not have a main stream enough appeal to warrant the investment as it would likely not make any return, where have we heard this before?


Putting aside human interest, the logistics...  Technically the story told in the produced film is far more technically and spectacular with the visual effects, so logistically yes of course the story of the book could be physically manifested, so logistics really comes down to copyright infringement and matters of runtime.

For instance the book takes you through the re-enactment of other films...


You can't show another film in its entirety within another film, however the text of the book doesn't do this, nor does it show us all of the Holy Grail, you get exerts.  The film of RP1 went with the Shining, seeing even the references to WarGames and Holy Grail as too niche, so I can make my peace with the films decision, but I can't say that either reenacting parts of another film were not possible.  Indeed in the case of Holy Grail, do we not have Spammalot still on stage!  An adaption of the original film, so there's logistical barrier, it's all legalities which are not insummountable and to make the book into celluloid you only have to reparaphrase the little to make the whole so much more.

That said, I like the current film, but it is not RP1.

Therefore, technically, logistically and legals surmounted you could film the actual text of RP1...

You just couldn't make it stick on the silver screen, it would not fly... Maybe Netflix could make it and maybe not into a film but a multi-part series?