I've just had myself into a complete frazzle, code yesterday was fast, rendering 120fps, the same code today was struggling to pass 11fps. And it had me pulling my hair out, of which I have little left to spare.
The problem?
I had been processing strings for specific patterns and only replacing them, so a variable in my engine might have the value "SCORE" and it'd replace the players score value directly into the std::string instance for display.
I however decided I wanted to compound all these reserved words to allow any value to contain any replaced value and also contain formatting, so I could so something like "You have scored %SCORE% today" and it'd just place the number in place.
I turned to boost for this, boost::replace_all, to be specific, and I had about 45 pattern matches which would try to replace any instance of the string in place.
However, this function does not look a head if the predicate is present in the source string, it's in fact very slow.
So code:
const std::string l_Pattern("%SCORE%");
std::string l_Source("You have scored %SCORE% today");
.
.
.
boost::replace_all(
l_Source,
l_Pattern,
Player::Instance()::ScoreAsString());
Would result in very slow performance, my solution is not perform the replace... search for the pattern predicate first:
if ( l_Scource.find(l_Pattern) != std::string::npos )
{
boost::replace_all(
l_Source,
l_Pattern,
Player::Instance()::ScoreAsString());
}
This latter code runs so much more quickly, I'm far in a way back a head of the speed curve, but I have this lovely dynamic placing of the variables into my rendering controls, and any control can receive any value just by my tweaking the loaded display script, so neat....
Anyway, I hope that helps. If you want to help me, pop over to my YouTube channel and hit that subscribe button.
A blog about my rantings, including Games, Game Development, Gaming, Consoles, PC Gaming, Role Playing Games, People, Gaming tips & cheats, Game Programming and a plethora of other stuff.
Wednesday, 31 January 2018
C++ boost::replace_all Slowed Me
Labels:
Boost,
C++,
char*,
characters,
Code,
Development,
example,
Language,
programming,
quick,
replace,
replace_all,
search,
slow,
speed,
std::string,
strings
Thursday, 25 January 2018
When Software Tries to be Cute
Developers of the world, unite, and stop listening to sales-folks who say that variety is the spice of life, that you need to make your programs do cute things, like vary the replies it gives. You are only causing yourself more trouble testing, debugging and annoying your users.
Users of the world, unite, and stop wanting stupid cute differentiation replies from programs to make you feel special. You are not special, you are one of very many using the same program, be like normal people and expect the action of something to have the general same reaction so you can see when things go wrong.
I bring this up, as I recently had the Ultimate Ears Blast App, and it was too busy being cute with "just a moment", "hang on in there", "be right with you" bullshit replies to actually work! Yes, it looked to me they were trying too hard to be hip that actually hit the mark!
And YouTube has just done the same thing, check this out....
Same machine, same time, same browser, same YouTube account target... Two different replies... Just to be cute, and one is broken!... GG YouTube, GG Google...
Oh, and has anyone actually ever worked in the YouTube website?... It's a nightmare to navigate, with things hidden and changed, as a content creator, you go to try and get your own home channel, it's a nightmare, you have to view the whole site, select "Library" and then "Home"... You used to be able to press one thing "My Channel/My YouTube", so simple? Why change it?.... To be evil of course.
Monday, 22 January 2018
C++ Simple Limits & Server Recase
Health & Myself
What a whirlwind few weeks I've had, first of all, I've had some minor medical work done so not really been in the mood to do anything very interesting except recuperate in my spare time. I've also got on-going dental treatment going on, so I'm doubly aggravated.
Next I have been so busy with work, I've had a change of job title, I've been effectively promoted into the lead developer role for the platform/product range I work on; this is sort of a defacto position, as I'm the ONLY developer working in this area at present, however I'm now officially the man on point and am about to reform a new development team around it. I will be working in Scrum methodology with this new team, we'll be pushing product to both Windows and Linux, Git will be our source control system (no matter what anyone else says) and I'm going to leverage C++ as the core product with tools all being produced in Python, very exciting stuff.
Server Issues
At home however, you may have seen this late night problem....
I have not, as yet, tackled this problem in any satisfactory manner; there's just been too much going on.
However.... I have a plan, a plan so cunning you could put a tail on it and call it a fox.
I had a look around in the case, and removed the bad drive, here it is....
This is an old drive first of all, and it was only 3.0gb/s SATA, but it was useful as part of my mirror, and without it I'm now naked. In my room/workspace tidy rambling video you will see I have a stack of WD blue drives on my desk, however I'm at pains to put them into this server, as the more space I give myself then the more data I have to move later, and the less places I have to stash that data.
What do I mean?... Well, that machine already has about 4TB of data in the two ZFS Pools and the one scratch drive, I do not have ANYWHERE else to put 4TB of data, and I can't afford a new drive, hence why I've carefully and strategically informed the wife I'm buying the off 1TB drive once in a while over the last year... Dropping a 4TB drive in the mix, she'll flip.
Recasing my Server & Workstation
So, my plan?
Well, first of all I have my main work station in a trusty, but now rather old, Coolmaster Cosmos 1000 case (you can see this case in some of the very early pages of this very blog)... Now, this is a very nice case, and has 10 internal 3.5" drive bays... So would be pretty nice for my server to move into, add all the new WD drives to it and voila a working server with expansion capabilities.... A recasing, that's a plan... Plus I get to perhaps look at that Xeon mod a year on and evaluate how it got along.... And of course more ZFS fun... Maybe a video about Git & setting up my own ticket handling system.
Right, that's the server... What about the now case-less workstation?
Well, I'm considering a new case, of course. Front runners are the Corsair Obsidian 750D as it has modular upgrade ability, and if I like it, I can get another and expand the server into it next year.
Infiniband
A long-term project is to consider an Infiniband link between my server and my workstation, we'll see how this goes along, not only would I need to purchase some adapters and cables, but I would need to switch my workstation into a new dual-boot as only Linux would be on Infiniband (and as you may have noticed Windows was on the list of platforms for my new role specification).
C++
Simple limits in C++?.. What am I talking about, hmmm, well I just ran into some code:
auto value (0);
if ( requisitValue < defaultValue )
{
value = requisitValue;
}
else
{
value = defaultValue;
}
Nothing wrong with this you may argue, however the developer hadn't looked at the values they were working with, the defaultValue for this system locale was ALWAYS the highest value on a sliding scale, the configuration insisted the default be the cap and so any requisite value would be smaller.
I asked the chap to have a think about this code, having explained the requisit would always be lower than the default, and asked him to come up with any improvements. He did....
auto value(
(requisitValue < defaultValue) ? requisitValue : defaultValue);
I asked him to rationalise this change, why had he done it?
- To meet the coding standard define of not assigning, but to initialise with a value
- To make the code less lines of code
I have no disagreement with the first point, the second... Not so much....
I do not subscribe to needing code to be smaller (less lines of code) so long as it's readable, as for my work maintainability far out reaches using less lines of code. Especially when the change made is exactly the the same resulting code, just the change is far harder to read.
(Don't miss-read this, I agree you should try to make functional code take less lines of code, but the above is white-space more than functional change, white-space on a modern compiler is NOT a problem, make your code readable before you start trying obfuscating functionality for fancy frills).
I stopped the developer in his tracks however, and asked him to pull up the document for the specification and describe "defaultValue"... "The maximum amount allowed in the value" he read.
So, changing the name of this value was the first step it became "MaximumValue". Use a meaningful name.
And finally, if you really want this decision to be a single line of code, how about:
auto value(
std::min<valueType>(
requisiteValue,
maximumValue));
Using the minimum function here, we make it clear we're doing a mathematical operation, it's a single line instruction (even if I do stagger it for readability over four), and we're not going to confusing the order of our parameters, so avoid introducing comparator ordering bugs later.
This is the simplest way to find a limit between two variables of the same type in C++, using std::min and std::max. Learn about them and love them.
The reply the young man gave me... "But changing the name'll mean I have to change hundreds of different places in the code!".... "Yes, so use find & replace in files?".... "Oh but what about all the other "defaultValues?".... "Why are they not in namespaces, or classes, or using other names?"... Silence.
Labels:
750D,
blog,
C++,
Coding Standards,
coolmaster,
Corsair,
cosmos,
examples,
failed,
hard drives,
issues,
mathematics,
server,
std::max,
std::min,
update,
xeon
Tuesday, 9 January 2018
Water Cooled PC's... The last harbour of the Elite System Builder?
Simply put... No, no I don't... And this isn't just some trifling aversion, I mean I have a real deep rooted problem with going and putting a water reservoir inside a machine, this is even before we consider the logistical challenges to installing a water loop. Lets delve deeper....
Traditionally PC's, and indeed most computers, have been air cooled, initially machines were pretty slow meaning the surface area of the chip alone was sufficient for heat dissipation (my 68000 equipped ST's for example).
However, as machines got faster so the electronic head began to build, essentially the more power the machine uses literally the more heat is put off, in the broadest sense thermodynamics demands that electrical energy moving the electrons inside the components not be 100% efficient and therefore some of that energy be lost, and it's only escape is as heat energy.
This was dealt with by the addition of extra surface area to chips, in the form is heat-sinks, many finned metal constructs stuck on, simply to provide the added folders of more surface area, indeed some components - or whole systems - can be cooled this way quite well.
Things never stay still, so as Moores Law gained traction into the 1990's fans were added to many systems to draw cool air in and over the components, specifically the processor or CPU, which is where I found my first system fan, on my Intel 480 DX4-100 chip in the mid 90's (prior to this my 486 SX-25 was still passively cooled, with just a heat sink!).
Since then the fans in my system have evolved over and over, and as a bachelor I had no issues with massively loud fans blowing or whirring systems... This is just what you had, usually tiny fans spinning incredibly fast, plus hard drives etc, PC's made a hell of a clatter in the late 90's and early naughties.
Enter the wife to be, and things had to change, so I looked at quietening the systems I use down:
And it became a bit of a tradition with each iteration of my work area to improve the sound aspects, even on systems not kept directly in my working area:
So now I have a happy-and-successful train of experience with both Knix, Sharkoon and Noctua fans, all excellent in their ways, I have experience with drive ordering, switching SSD's, orientating my power supplies, smoothing dust filters... The systems I run close to me are whisper quite, yet extremely powerful, and never get too loud, my typing is always the loudest thing around!
Water cooling however is "silent".... Erm, reality police, no it's not.... You still have the sound of a power supply unit in your machine, and unless you're absolutely crazy you don't really open them up and try to passively cool them, so it will have a fan in there. I can switch the fan out for a silent brand, voiding any warranty, but really is it going to be silent? No, of course its not.
So, what do I gain with water cooling? Really, what do I personally gain?
- Worry about the joint fittings
- Pump seal
- Block corrosion & blockages
- Coolant contamination/algae growth
- Tube decay
All leading me to think about catastrophic failure, which is coolant, be it electronic safe or not (most likely not) spilling out everywhere, literally hosing my machine.
What do I get with a fan? A high temp warning, or an indicative sound, and the chance to clean things up with a blow of air!... Air, not water, air, not worry.
And I'm going to sit like this forever I think, I see JaysTwoCents, I see ScienceStudio, I see Linus Media Group and a plethora of other skilled and knowledgeable folks on YouTube and at large vaunting water cooling all the time, but truth be told... I can't ever help but wonder if this is just folks looking for someway to express just how superior they are to others.
Lets face it, the PC master race exists, we're here... And some of us have been on the band wagon a long long time*, and it's the need in us to express this that I think is this very trait driving this die-hard gamble on water-cooling.
Anyone, and I mean anyone, can build a modern PC... You literally buy the parts and slot them together like the ultimate in expensive Lego... The elite caché of being able to do this once highly skilled and technical task has been ebbed away, the fire was literally stolen from us and passed to the masses.
What therefore do those of us, whom endured being the nerds and the geeks and the outcasts so long, turn to in order to almost prove our superiority, how to we edge the masses back out of the picture? Well, I think that's water cooling**.
Water cooling is nothing but a risk, you can't scale it, you can't use it in production, you can't easily maintain it, and the ultimate common denominator is spillage, that liquid does not want to stay in that loop... Where as air is ubiquitous, your kit can cope with being submerged in air all the time!
The final incarnation of this is perhaps the most perverse in "ultimate", to exclude the masses and that is the niche phenomena of submerging a PC in mineral oil... As seen here...
The ultimate irony of this entertaining video being the CoolMaster*** sponsorship at the beginning, being for a CPU water cooling kit... CPU only, not scaling to the GPU as well... and vaunting "silent" fans... Just put the damn silent fans in your case, on your CPU, let the air do the job...
You can argue with me about the thermal properties of water being so much more than air, meaning you can "push your hardware further, faster than before", that maybe so, but it's again an edge case, you can over-clock on air, and if you're buying a new system to overclock you're falling straight back into my master-race theory, you're striving for more than the public can reach, you're pushing the envelope, you're ultimately trying to be more interesting than you actually are...
Good luck, really, truly, good luck, I can't wait to see your video posts about it, and I will watch with baited breath. However, my breath will ultimately be passing through and cooling an air cooled machine, as it's simply safer, easier and more maintainable, and I'm not worried about being boring or proving anything.
* Anecdote of the day, one kid at school found out I had an Atari ST, and he offered to "Swap you a Neogeo with Contra for it right now"... I laughed in his face, I in fact looked at him like a cockroach; as he was being nasty; "do you think all I do is play games?" He had no concept of using a piece of electronics beyond plugging it in, I was creating. I went home each night and I tinkered with STOS, later I tinkered with Pascal, and I'm paid to now tinker with code all day... I don't think that lad is paid to play his Neogeo, or any other console, and no it's not a twitch streamer - I've looked.
** I have a very similar theory as to why very boring people get a piercing or a tattoo, they've no idea what it means, nor any idea why, but they can't help but point it out... Imagine a 1990's computer geek getting a skull tattoo on his face... Same thing with water cooling.
*** I love CoolMaster cases, but I never want to touch these kits....
Saturday, 6 January 2018
World Cup 2018 Group First Leg Predictions
Before all the Octopi, Squirrels, Cow-Pat Bingo and whatever else gets rolled out for the Football (yes, not Soccer folks) World Cup in Russia I thought I'd give you my game by game predictions... It might be worth an accumulator? But you may just find lots of my own personal bias.
Group stage - First 16 Games Predicted...
Game 1: Russia v Saudi Arabia - Russia 2 to nil, as hosts I think they stand a real chance to put a stamp on the game.
Game 2: Egypt v Uruguay - Egypt 1, Uruguay 1 - I feel that Egypt have some talent for them and this will over arch Uruguay's historic tenacity.
Game 3: Morocco v Iran - Morocco 1, Iran 0 - This is a pretty even match in my opinion, however, I believe Morocco will pip it.
Game 4: Portugal v Span - Portugal 1, Spain 2 - Very hard to pull this one, it's going to either see lots of goals or not very many, but I'm going to edge Spain over the Portuguese as they'll want to put a mark on the score card against their regional adversaries after the Spanish turmoil of 2017.
Game 5: France v Australia - France 2, Australia 0 - I'm sorry to say I don't think this'll go anywhere except France's way, Aussie still rules!
Game 6: Argentine v Iceland - Iceland 1, Argentina 0 - As the chap whom has helped save the wife's life from cancer is Icelandic, I'm voting with my heart and my hopes.
Game 7: Peru v Denmark - Denmark 2, Peru 0 - I've got to say the Danish will enjoy this one, with no real rivalry on the international stage I can only say this may feel like one of those wonderful friendly world-cup matches.
Game 8: Croatia v Nigeria - Croatia 1, Nigeria 1 - I think things maybe slightly swayed on the Croat side, but Nigeria squad isn't to be sniffed at, pulling things even.
Game 9: Costa Rica v Serbia - Serbia 2, Costa Rica 0 - One of those one-sides group matches, but I believe the Costa Ricans won't let the Serbs have it all their own way.
Game 10: Germany v Mexico - Germany 3, Mexico 1 - My git feeling is of course for German dominance, however I don't think Mexico will let it go into a Teutonic slide.
Game 11: Brazil v Switzerland - Brazil 2, Switzerland 0 - Very one sides I'm afraid, though I think the Swiss will play good structured football.
Game 12: Sweden v South Korea - Sweden 2, South Korea 1 - I actually think this maybe nil nil in the full-time mark, but if I'm taking my head at true value Sweden should pull through.
Game 13: Belgium v Panama - Belgium 2, Panama 0 - The Belgians, if they can hang together as a team, will walk over the tiny Panama offering, however it'll again be a friendly feeling game.
Game 14: Tunisia v England - England 1, Tunisia 0 - We English will probably cock this up mightily, giving everyone at home heart failure to just about pull a head. However, if the English score early they'll go off the boil; as we always do; and there's potential for a real upset.
Game 15: Colombia v Japan - Colombia 2, Japan 1 - I think the Japanese will play well, however can they over come the South American side?.... I'm not certain.
Game 16: Poland v Senegal - Poland 1, Senegal 2 - I think the African side will push up forcing the Poles to equalise, but there'll be a last minute push from one or the other, I'm very split on this it may go even, but ultimately I think it'll be down to whom is most hungry.
That's the end of the first match in the Group Stages from me, more will follow...
Friday, 5 January 2018
Bad Code...
You know when you open someones code and you find this inside a class function...
unsigned short currentMessageOffset = this->CurrentMessageOffset;
That you're in for a rough ride.
First of all, WHY assign the member value on the right to a local? No-where else in the class is this value edited or read, so there's no need to assign it to anything.
And then the naming, this naming of something local with the same name, and it is the same name, despite the capitol leading letter, it's the same name, just makes this utterly useless.
All this before even mentioning that the code is an assignment not an allocation, so annoying.
Wednesday, 3 January 2018
Ultra Cheap ZFS Array
Make your own ZFS array (mirrored) with USB Flash drives, for cheap!
Since this... interesting post of mine... has only about 10 views, and my tech items usually get a few hundred, I figure somewhere along the lines it got trampled by my silly New Years post....
Subscribe to:
Posts (Atom)