« first day (142 days earlier)      last day (4799 days later) » 
00:00 - 20:0020:00 - 00:00

12:05 AM
simplest solution would be
void asdf(std::vector<double>& a) { a.resize(10); }
 
my washing is taking forever :(
 
12:50 AM
2
Q: Unexpected order of evaluation (compiler bug?)

user647445I'm not sure if this is a gcc bug or not, so I'll ask: unsigned int n = 0; std::cout << n++ << n << ++n; gcc gives the extremely strange result: "122" which AFAICT is impossible. Because << is left associative, it should be the same as: operator<<(operator<<...

Yet another i++ + ++i. Please vote to close.
 
 
8 hours later…
9:18 AM
the sheer silence
 
9:36 AM
broken
 
It's some kind of Heisenberg effect, talking about the silence has a tendency to break it. en.wikipedia.org/wiki/Uncertainty_principle
 
it often comes back just fine enough
 
 
2 hours later…
11:29 AM
if the user is typing data like... NUMBERS:1 2 3 4 5 6 7 8...and we dnt know the number of elements he ll type.in such cases how will we store numbers in array
 
@user388338 You are probably better off using an std::vector, as you can have that grow as needed --and is less error prone than manually managing memory
 
ok david thanks
@david how will you do the same thing in c
 
I myself... would probably implement a vector and then apply version 1 :P
Seriously, if there is a limit in the number of elements, just create an array big enough
If you cannot, then you will have to manually manage the memory, malloc() a number of elements, and realloc() as needed when you need more space
Now, for the malloc/realloc version, that is basically implementing a C version of the C++ vector. Since I am not a C developer, I cannot point you to any lib that does it, but I can only assume that this has been done before
 
well i know the maximum limit..but then i dnt know for how many iteration i should execute loop body to fill array with values
 
Take a look at the scanf function (and variants) as they will probably have enough information for you to interpret when the line ended.
 
11:39 AM
well, a vector just wraps up the basic array so that if you try to add one more element than the array currently hold, it makes a new one, copies over the data and deletes the old one
 
In particular, scanf will return the number of elements read, so if you loop something like:
int data[MAX];
int counter=0;
while ( scanf( "%d", &data[counter++] )==1 );

(or the like, I have not compiled/tested that) it should just read a bunch of integers, when the loop completes counter should contain the number of elements read. Again, disclaimer: it's been years (over 10) since I coded C, so take this as a hint, not a solution (scanf arguments might have to be different, you will need to remove the "NUMBERS:" from the input before looping...
 
11:54 AM
@david its not working :(
in the desired way...its not coming terminating loop on pressing enter
 
Not working is kind of a general statement...
:) You were hiding requirements.... the input does not terminate after the numbers, only the line!
 
i mean the loop is not terminating on coming to next line
 
then try reading the whole line with getline(), and then using sscanf. sscanf will provide you (don't quite remember how) how much of the string has been read
 
ok i try
 
there might be better ways... any C developer around?
Is the number of arguments small?
 
12:02 PM
i know a bit of C...
 
The question is what would be the idiomatic way of parsing "NUMBERS:1 2 3 4\n" from user input, where the number of integers in the line is unknown and the input does not terminate after the \n
 
std::vector<int> v; while (std::cin >> x) { v.push_back (x); }
 
@wilx that is C++ (not plain C), and it does not even fulfill all the requirements (it will keep reading after \n
 
If it is per line, well, then I guess reading the line into a string first and using std::istringstream instead of std::cin.
Oh, sorry, C?
 
i can't think any lib function. I'd remove NUMBERS: and assure there's only one ' ' between ints, so we have "1 2 3 4\n". Then get chars from begin until meet a ' '.
I try to do a sort of pseudocode, wait..
 
12:07 PM
scanf("%[^\n]", &buflargeenough); while (sscanf (buflargeenough, "%d", &x) == 1) { /* something with malloc()/realloc() and stuff... */ }
 
is this gonna be a real perf issue: msdn.microsoft.com/en-us/library/b6801kcy(v=vs.71).aspx ?
 
@Tony: IMHO not at all.
 
@wilx while (sscanf( buffer, "%d" ) == 1 ) is an infinite loop, the pointer is not being advanced so it would read the first element (if present) infinite times
:)
 
Yay!
 
I seem to remember that gcc had some extension to obtain the number of chars consumed by sscanf, but don't remember which, a manual loop seems like the best thing to do (locate beginning/end of each number, atoi()/sscanf() from there...) but that does not seem too simple
 
12:11 PM
what about this? pastebin.com/sZPAYkvf
 
@Tony I don't think that is really a performance issue, but just add the != 0 and make the compiler happy
 
are you able to let the user define how many numbers they want to enter? that way you can allocate an array big enough, and ask them for that many numbers
 
@user388338 maybe it is actually a better idea if you ask that as a question in SO :)
 
12:48 PM
char line[MAX_LINE_SIZE];
while ( scanf( "%[^\n]", line ) == 1 ) {
   int pos = 0, number, read;
   while ( sscanf( line+pos, "%d%n", &number, &read ) == 1 ) {
      pos += read;
      printf( "number %d, length %d, pos %d\n", number, read, pos );
   }
}
 
 
2 hours later…
sbi
2:47 PM
@Tony I actually knew this to be a weak spot in my argument, but, after some contemplation, dismissed it on the grounds that even C++ chat room participants wouldn't be anal enough to point out that, when people congregate, the result might not always be a congregation. <sigh/> I really should have know better...
 
@sbi: What are you talking about?
I really hate it when people come on here and reply to messages hours or days old
 
sbi
Hi @Dead. You still alive? (Sorry, but I really could not resist.)
2
 
no, my skeleton is typing
 
sbi
@DeadMG That's what the little arrow to the left of my message does. (This, and many other things, are described in the newbie hints. You might want to have a look at them... ;-) )
 
hmm
flag, star, pin, permalink, reply
don't see a "what on earth are you on about" button
 
sbi
2:52 PM
@DeadMG That's the "down arrow" button you clicked. And the arrow between that and my message... Are you pulling me leg? You do know that feature, don't you?
 
oh that button
the contrast on it is hardly high enough for my busted eyes to pick it out
 
sbi
3:17 PM
Wow. I lost 170 rep last night, no explanation given. Since I'm sure I triggered a rep recalc not two weeks ago I'm really surprised. Anyone out there knows what this can be attributed to?
 
you overchecking your rep?
it's hardly the most relevant thing in the world
 
sbi
Oh. Never mind. I gained 30, not lost 170. <blush/> Sorry.
 
loplowned
 
sbi
Well, at least that's my conclusion from looking at my stats page. I had +30 today (all old questions), so I suppose I must have missed the 1 turning into a 2...
 
what I don't get is
why is rendering such an expensive operation?
like
it should only be a couple hundred thousand verts or something
 
sbi
3:23 PM
@DeadMG Because actual masons have to stand on a ladder applying the render? People are expensive.
 
not funny :(
 
poor toast, rofl
hmmm
Lounge<C++>: Where safe sex is less common than safe exceptions
opinion?
no, wait
where sexual safety is less common than exception safety
 
sbi
@DeadMG You don't really want to put "C++" and "sex" into the same sentence??! I mean, this is the C++ chat room, alright, but we do have some taste! Or do we?
 
lol
room topic changed to Lounge<C++>: Where sexual safety is less common than exception safety
2
that answer your question?
 
sbi
3:39 PM
@DeadMG What do you mean? Do you really think, we have no taste, just because you are a tasteless, erm, individual??
 
hehehe
I don't see why it's so tasteless
 
@sbi hahah
room topic change twice in 48 hrs
what's going on?
 
well
what's going on is the previous room topic sucked
and I had to come up with something new rather pronto
 
sbi
@DeadMG We can tell that by just looking at it. :)
 
lol
well come up with something better then
 
3:44 PM
I think that keeping sexual safety in this room is far more easier than to keep exception safety in my programs.
 
@AProgrammer I agree
lol
 
sbi
@DeadMG It's far easier to lean back and mock at what others do, than to come up with something better.
Anyway, I'm gong to be afk now, need to pick up the kids...
 
ok have funsies
 
@DeadMG what's new?
 
@Tony: Not much?
 
3:50 PM
how boring
 
yeah
I've been thinking about writing a kind of semi raytracer system
basically because I can
 
Semi?
 
well
it would only use raytracing for direct light, adaptive aa, and a couple of other things
but I'd basically have to write all of it from scratch
 
@DeadMG if I even knew what that was for, I'd say "Coool"!!!
@DeadMG google gave me answers.... interesting....
sounds difficult however
 
oh, no
writing a raytracer is not hard
writing a raytracer that can output at 1080p in real time, however
 
3:57 PM
is hard
 
very much so
 
so how long you been into graphics type stuff?
 
ehm
just over a year, I'd say
 
oh wow
 
been writing my own stuff from scratch
 
3:58 PM
so no libs?
 
but, mainly, it's been hard to get content imported
only DX, WinAPI and STL
 
wow
impressive!!
 
heh
you can say that if it works
 
do you have a blog or site?
 
no
 
3:59 PM
darn.... be interesting to have look at the stuff you been doing
I might learn something....
 
maybe I should just use .X meshes
but D3D11 doesn't support them :(
 
wish I could help
 
I still don't see how you would go about a semi ray traced scene
 
the key to performant ray-tracing, I feel, is going to be limiting the rays
1. Trace (screen res) rays from camera to impact to determine pixels. 2. Trace rays from pixels to light(s) to see whether or not to light them. 3. Light pixel or not appropriately for each light.
as opposed to, raytracing the whole scene
 
well, how ever you go about ray tracing, you still need to do this for each pixel being rendered
 
4:04 PM
of course
but, that's not that big a deal
UE3 running on 360 renders 10million pixels a frame
 
yer, but that is not suing ray tracing
 
of course not
but then, I only need to render 640x480 pixels a frame
well, maybe more, depends on how the aliasing works out
 
each ray has the potential to reflect and refract of ever object in your scene
 
that's what "semi" is for
i.e., it's not going to do that
 
so its going to be a crude ray trace, simply working out what object each pixel initially hits and then what light shines on that point on the object?
 
4:07 PM
yes
but I believe that it can deliver much better image quality than the current systems and potentially at a higher performance
because for shadows right now, you have to render the scene multiple times, and etc
whereas the crude ray trace only has to render once
 
current graphics cards have become very good at working the way they currently work. This is kind of doing the process upside down
 
I know
and I doubt that the result will get anywhere
it's Curiosityâ„¢
 
If you could work out how to make use of shaders for this it could be very good
 
D3D11 has Compute shaders
but I'm going to implement entirely on CPU first
 
It might be an interesting way of calculating shadows
you could render like a light map as the camera can see the scene, and use that to scale the brightness of pixels
 
4:11 PM
no
that's how current rendering works
and I'm aiming to avoid it because of the resolution issues
if you render a shadow map, it has a fixed resolution, and you can get aliasing issues and things like that
whereas semi ray tracing does not have that
 
no I mean render the scene twice, one you calculate how bright each screen pixel is, the next time is more like a conventional render process but a pixel shader uses the ray traced light values to apply shading and so forth
That would be for shadow maps from the lights point of view
which from what I have gathered, is not really done any more, shadow volumes seem more common now
 
never seen shadow volumes personally
 
it will be very interesting to see what you can get working though. I do think that soon games will be done raytraced at run time. We just need enough threads and a very solid way of letting them access read only from the scene's geometry
 
the trouble isn't that, necessarily
it's tracing 300,000 rays
with 200,000 vertices
 
I do think though that having pre-calculated light maps for scenes is wise. if you know what lights are static through out, then you can just store the resulting light value once
 
4:17 PM
yes
UE3 can generate some very detailed pre-calculated light maps
 
its things moving that makes it a pain in the ass :P
 
hell, if things didn't move, we'd just photorealistically raytrace every scene
 
I suppose, if done at a low resolution, and with a simplified ray trace algorithm and relatively simple scenes, real time ray tracing shouldn't be that unreasonable to have
 
well
the main thing is that it prevents re-rendering the scene from many perspectives
at least, for the generation of lighting and quite possibly other similar texture projection based techniques
 
 
1 hour later…
5:31 PM
can any of you suggest me a decent profiler?
 
@BlackBear you should probably add what platform you want the profiler for
 
@DavidRodríguezdribeas for windows
xp
 
Cannot really help there. I haven't done any profiling in Windows (for what matters I have done just a few profiling in linux...)
 
never mind. but I've both win and linux, so.. what have you used on linux?
 
@BlackBear Some versions of Visual Studio come with one. But tbh, for many purposes I'm starting to believe that the best approach is simply to stop the program in the debugger a couple of times throughout execution
since you're looking for the pieces of code that take the most time, you're pretty much guaranteed that you'll find them that way
 
5:39 PM
@jalf my problem is that i'm developing a game, so i can't stop it
 
@BlackBear Can't you just let it run? Maybe script the input so you can replay it (that'd be a very valuable feature for general debugging as well), but even just standing still and letting the game render the world while you stop it in the debugger every once in a while, would be useful
Are you using DirectX or OpenGL?
For DX, load up PIX and see what it tells you. Most likely, it's the GPU side you need to optimize, so PIX would probably give you more useful data than a profiler
 
If you can get an almost stopped box (no X, no services) oprofile is probably the most precise
 
@jalf i'm using the xna. i just lost 5 frames/second and don't know why
 
ah, try PIX then
 
did you change directx between debug and release modes?
 
5:42 PM
it records a ridiculous amount of profiling data for everything that happens on the gpu
 
kcachegrind is a bit more "user friendly" kcachegrind.sourceforge.net/html/Home.html
 
thanks guys, i'll give a look :)
 
6:09 PM
@BlackBear your using xna on linux?
I need to improve my linux foo. Not really started properly developing stuff as still meant to be doing uni work, but what I have done so far has relied on me not doing anything wrong :P so I've not done much ¬_¬
 
@thecoshman i don't think it's possible to use xna on linux. with wine perhaps..
 
that what I was confused about. You said you that where doing both win xp and linux, but also that you where using xna
though they could have just been to separate non-related facts
 
7:12 PM
Yay, g++ segfaults when precompiled header is used. How can you not love this compiler.
 
@thecoshman yeah. they're separated, i'm using xna on win but have linux too (which i use for other things)
 
7:35 PM
@PiotrLegnica in fairness, I believe you're something of a rarity if MSVC has never crashed on you either. ;)
but that doesn't excuse anything
 
7:48 PM
@jalf It didn't, but it did link the binary to both debug and release CRT.
 
someone at work today said: "There is no perf difference between C# and C++"... I'd say that is a lie, what do you say?
 
I'd say it's a nonsensical statement
Just like the opposite would be
 
@Tony I'd say it depends
 
Arg... rep available as low hanging fruit and I avoid to grab it on moral grounds... worse than that, I reject marking the question as a duplicate (shame on me) just not to make it easy for a particular user to get the answer...
 
It's as absurd as saying that yellow and blue taste differently
or that english is faster than french
Languages.... don't.... have... a.... speed.
 
7:53 PM
It's good that I am not a moderator, I would have deleted the answer straight away... I would have removed the user altogether!
-1
Q: How to get size of an array using metaprogramming?

There is nothing we can doHow to get size of an array using metaprogramming? Multidimensional would be also appreciated.

 
Write some code, pass that code through a specific compiler, and run it on a specific computer, and it has a measurable speed
But an abstract programming language doesn't have a speed
 
@jalf I know that a language doesn't have speed, but the code in C++ is run closer to the machine, so I guess it can be made to run faster then C#, that has GCC etc...
no?
 
What gives you the crazy idea that "closer to the macine" is faster?
 
@DavidRodríguezdribeas I would ignore that guy, he is known to piss people off
 
Assembly is closer to teh machine, and in general, human-written asm is going to perform horribly on a modern CPU
 
7:55 PM
He is known to piss me off, that for sure!
 
because taking into account all the complexities of a modern CPU is just too complex
 
@jalf less layers in between
 
we can do it in individual small functions, but when writing a program? We're going to write far more inefficient code than a compiler would
What layers? The layers are eliminated during compilation
What executes is machine code in both cases
What langauge it started out as is irrelevant
 
true, but you have the GCC running as an additive, etc... on .NET
doesn't that affect things, even ever so small?
 
in C++, you have destructors running
 
7:56 PM
or have I gone bonkers
 
In both languages, everything you allocate has to be cleaned up
What makes you think one way of cleaning up is automatically and always faster than the other?
 
@jalf not saying it is always like that
 
And what does "on .NET" mean? Does C++ run "on the STL"? .NET is a lot of things, but the code that executes is JIT'ed to native machine code. It can call out into a lot of library functions from .NET, sure, and .NET defines a lot of thnigs that happen before execution (such as the intermediate bytecode format)
but it isn't really a layer "between" your code and the CPU
 
so why do they use C++ for 'high perf' apps more often then .NET framework
 
Who are "they"?
 
7:59 PM
developers
 
Developers of what?
 
I'm trying to clarify something here because I wasn't sure I didn't know the answer
you don't have to attack me for it
 
the main problem with C# is that you can't control, unless you pull some magic, when garbage collection will actually be done. C++ it is up to you to manage this overhead, so you can get a bit more controll over it
 
I'm not attacking. I'm asking a very blunt question ;)
 
00:00 - 20:0020:00 - 00:00

« first day (142 days earlier)      last day (4799 days later) »