Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 28 Feb 2011
Offline Last Active Today, 08:53 AM

#5272402 C++ exceptions

Posted by Bacterius on 23 January 2016 - 03:56 PM

Also, queue push, regardless of the prototype, can fail. It can fail if it fails to allocate memory, and it could potentially have a ring buffer implementation, that would run out of queue space sooner.


Not necessarily. If the queue uses a fixed-size circular buffer then pushing an item into it can never fail. In many situations old queue items can be discarded over new items.


Using operations that cannot fail whenever possible and making use of transactional memory patterns for destructive operations that could fail is a good way to increase your software's reliability. But that may be overkill for many applications such as games; after all, in a game most of the time you can just abort on error, as long as the player's save file is not corrupted and not too out of date, no harm done.


Although I agree that just checking the prototype isn't enough by itself; you want to have a good read of the library's documentation and maybe peruse its source code a bit to see how it handles errors. When you know for sure that functions that return void legitimately cannot fail, then you are good and can just refer to the prototype for quick reference. Of course, if the library is written by baboons that use longjmp to escape to god knows where on error, do you really want to use it in your software that's supposed to be reliable? smile.png

#5272071 Risks Of Using Computer As Webhost?

Posted by Bacterius on 20 January 2016 - 05:52 PM

Honestly it's not worth it. You can get away with hosting private, low-availability or low-bandwidth services locally, but for anything more serious such as a public website or a game server you will never meet an acceptable uptime, someone might flood your residential line (super easy) or, worse, if you have a data cap and have a shitty ISP you may find overnight that you've gone 300% over, have been charged $600 over-cap and have had your subscription suspended.


You can get a shared VPS for as low as a couple dollars a month and a dedicated server for $30/mo or less, the difference is they will be sitting in a data center connected to a fat network pipe, will have better uptime, and you can actually use them for mostly anything you want (for many ISP's hosting commercial servers, torrenting hubs or even game servers is against their terms of service).


Also don't forget that if you host a server at home that is separate from your own desktop/laptop/whatever (which is probably a good idea) then you also need to pay for the electricity to run it; and you may find that comes out about as (or more) expensive than just renting hosting... having an appliance running 24/7 is actually pretty costly these days even if it doesn't draw much!

#5270811 Weird access violation when copying data

Posted by Bacterius on 13 January 2016 - 02:24 AM

Imagine if the entire forum contained "deleted post" in every post of every thread. Please don't remove your questions, it helps no-one and simply means people in the future are led to this thread by its title and find... nothing sad.png if you find your solution please share it for future visitors!

#5270499 Render to a texture

Posted by Bacterius on 11 January 2016 - 01:07 AM

I believe the swapchain is only used when you commit the backbuffer's contents to your display device using the Present() method. If you are just rendering to a texture, then you just don't present, after drawing you can then retrieve the contents of your texture and do whatever you want with it.


I am pretty sure if you are only doing offscreen rendering (for instance some command line conversion tool) then you don't even need a swapchain at all.

#5270228 One function for several structs in a void**

Posted by Bacterius on 09 January 2016 - 12:34 AM

*ppVerts is of type void*, so you need to cast it to your array's type (PosCol* in this case).

#5269266 Criticism of C++

Posted by Bacterius on 04 January 2016 - 03:48 PM

Which is just the issue... pointer arithmetic that lands outside the bounds of an array is undefined behavior. I'm not going to argue that this makes 99% of all programs ill-formed (with haphazard results) because every pointer arithmetic bears a result that is outside the bounds of some array (and given the fact that there is argv, there is always at least one other array).


... what? not some array, the array that is involved in the pointer arithmetic expression! And while that specific part of the standard seems arbitrary in light of the modern, unified, fully byte-addressable memory model of today's architectures, it makes more sense when you view it in the context of segmented memory architectures, where in C you still only have, say, an int* pointer type, but you could have two int arrays in two different memory segments, and it's just not possible to meaningfully, say, subtract the two array pointers, or add an integer to one array to reach the other somehow; with this in mind it makes sense to not have distinct arrays be able to interact in any way (not that most code does this anyway)


EDIT: I think I see your misunderstanding now; the standard states that a pointer not otherwise part of an array may be treated as a one-element array in the context of pointer arithmetic (it is actually very clear on that point)


I agree some aspects of undefined behaviour can seem punishing in that a meaning could have been assigned to the operation that everyone would have been happy with and it would have made life much simpler. But, these things were decided upon a long time ago, and in many cases there were historical reasons for why the standard is written a certain way.

#5268988 How long does the C/C++ preprocessor keep going?

Posted by Bacterius on 03 January 2016 - 08:12 AM

The algorithm followed by the preprocessor is actually quite elaborate and involves stacked contexts to correctly handle nested and/or recursive macros (for instance if a token is expanded using some macro, then that macro will not be considered in expanding the resulting token). Probably the most direct way to fully understand the system, if you want to, is to read the docs and maybe even the internal docs.


But in most cases the preprocessor can be thought of as a process that does a single pass over the input stream, keeps track of all preprocessor macros encountered so far, and tries to expand each token according to these macros. If a token is encountered before the macro that's supposed to handle it is defined, the token will be left untouched.


Be aware that despite its apparent simplicity, advanced use of the preprocessor is typically not portable; things will work on a particular compiler and will break horribly on another because it doesn't expand your tokens correctly or somesuch. If your preprocessor definitions are growing out of control, consider reviewing your design to see if all these macros are needed, and then think about using a more specialized preprocessing system like m4 or similar.

#5267590 Multiplication support in GLM

Posted by Bacterius on 22 December 2015 - 10:28 PM

It doesn't look like anything geometrically, it's just component-wise multiplication. One typical use is in blending, where you might multiply colors together channel-wise. Not all vec3's are geometric, sometimes they are (ab?)used as a bag of three related values.

#5267102 What will change with HDR monitor ?

Posted by Bacterius on 19 December 2015 - 11:12 PM

Since the original question was "What will change with HDR monitor?"; if the monitors truly are HDR (like Hodgman said, HDR is quite overused by marketing... what it really means by HDR monitors "depends") then what will change for sure is your electricity bill. A monitor that can show a picture in a dynamic range around 4-10 times higher is bound to consume much higher electricity when the "shiny stuff" lits the pixels.


Funny how "staying green" slogan is also important.


If the monitors had a high enough dynamic range then our GPUs might in contrast use less power as they won't need to do things like tonemapping, bloom, lens flares and so on, as the monitor and our eyes will do it automatically, so we may actually save electricity in the long run! laugh.png (although we may overall lose due to people accidentally setting fire to their homes and losing their eyesight after displaying a rendered sun on their monitor unsure.png )

#5264540 PRNG Question

Posted by Bacterius on 01 December 2015 - 11:28 PM

Bacterius, so you're implying I should use a ctyptographic algorithm to create my random numbers?


I'm saying that it's one surefire way to do it (that also provides a bunch more advantages when done right, such as an extremely small memory footprint, the ability to seed, zero issues with poorly distributed seeds, good parallelization properties, optimal quality of output, and effectively infinite period). Sure, they may be slightly slower than a highly optimized dedicated generator, but:


 - random number generation is almost never the bottleneck in software as almost all generators are completely CPU-bound (and if it is, there are ways around that, and if you seriously need every last clock cycle for some embedded or HPC task then you are definitely an outlier and already know the tradeoff between output quality and the amount of work you'll need to put in to actually achieve that)

 - on the other hand, random number quality is actually a much bigger deal, and you avoid plenty of subtle issues with the way "dedicated" generators expect to be used, e.g. "weak seeds" or the all-too-common "yeah, the first few bytes kinda don't really look random, just skip them" defect


So, yes, it's a heavy-duty solution, but it's a flexible one that I've come to rely on and that has never once failed me. Why settle for anything less when the cost is so low, and the benefits so great? I have nothing against things like the Mersenne twister or xorshift, they are nice and noteworthy algorithms in their own right, I just find them inferior in almost every way to the above when it comes to practical matters. Necessary reading if you are interested in knowing more.

#5264452 PRNG Question

Posted by Bacterius on 01 December 2015 - 12:56 PM

As far as I understand, numbers produced by a PRNG will only be random relative to other numbers from that same sequence of numbers, not relative to numbers from a different sequence (with a different seed).


Only true for crappy PRNG's.


If you want to generate random numbers from a sequence of seeds (not a sequence of random numbers from a singular seed), look into hash functions instead.


Sure, what you're looking for is the term "DRBG" (deterministic random bit generator) which can easily be built from hash functions, they tend to be a bit slow with hash functions though. Better to build them from block ciphers, it's more efficient.

#5264280 Casting a vector of arrays

Posted by Bacterius on 30 November 2015 - 12:44 PM


I don't know what C++ standard you use, but it's not true in C++11, which says at http://en.cppreference.com/w/cpp/language/types

I wouldn't say it's not true. char is still implied to be unsigned, but it is a distinct type from unsigned char for compiler.


If you perform numeric operations with char, it is gonna result to same value as if with unsigned char. Also if you compare char and unsigned char memory bits, they are gonna match for every value. They are just considered distinct types, so "unsigned char" in c++ code is just a water for compilation mill.



Whether char is signed or not is up to the implementation. Hell, modern compilers even let you choose, e.g. gcc with -funsigned-char and -fsigned-char.

#5263801 Lerp vs fastLerp

Posted by Bacterius on 27 November 2015 - 05:35 AM


when does the first form produces a different result than the second form?


They are equivalent.

a * (1 - t) + bt //Multiply a into (1 - t)
= a - at + bt //Rearrange to see the end result better...
= a + bt - at //Take the common term 't' and put it outside the expression
= a + (b - a) * t


I think OP is aware of that, he is probably asking regarding floating-point. The two expressions are not equivalent in general, for instance if a = +infinity, b = 0, t = 0, then one of them evaluates to +infinity while the other one evaluates to NaN. I'm sure you can also come up with all sorts of fun examples that the two expressions aren't equivalent using catastrophic cancellation, denormal numbers, or other such IEEE 754 goodies cool.png

#5263296 C# System.Numerics.Vectors slow?

Posted by Bacterius on 23 November 2015 - 12:38 PM

Those look like SIMD registers to me. xmm# instructions are the SIMD registers for your CPU. It just seems that the C# compiles to some pretty inefficient output. I see some extraneous shifting and moving. It's funny because it is doing MOVAPS but immediately performs MULSS instead of MULPS. It looks like it's pulling out single pieces of your matrix one at a time, placing them into the xmm registers, and then performing MULSS on a single scalar, rather than loading up 4 at a time doing doing MULPS. I have no idea why though, (here comes random guesses) maybe the memory alignment is poor, or the transforms are stored transposed in memory.




On AMD64 the SSE instruction set is used by default for any floating-point computations instead of the x87 FPU.

#5260542 Unrestricted while loop?

Posted by Bacterius on 04 November 2015 - 12:41 PM

Most GPU's are non-preemptive, meaning that once your shader is running... it will run to completion no matter what, without letting other stuff like, say, rendering your desktop, run in parallel. In other words your screen will freeze and if you have a driver watchdog it will reset the driver after some number of seconds.


To do what you want you should just get each invocation of the shader to do N passes on each pixel, and accumulate the results, where N is a reasonable number (large enough that you're not invoking a shader run for every pass, but not too large that your shader takes too long to run). If you are using a dedicated second graphics card not connected to a monitor then N can be as large as you want.


That way you can see the results of the iterative passes, N passes at a time. You'll know if N is too large if your desktop feels choppy to use.