|
Glasgerion posted:Resurrecting a question from before because I phrased it vaguely and still haven't gotten it right after messing around with it for hours. I'm trying to use the pdcurses library with mingw on windows vista. Can someone tell me how to set it up? I'm not real familiar with this sort of thing. You need MSYS from the Mingw site. Use that to run the makefile in pdcurses. After that's finished just setup your environment to check the pdcurses directory for include files and the win32 directory in that for the library.
|
# ? Nov 26, 2008 07:04 |
|
|
# ? Jun 1, 2024 21:29 |
|
This is more of a data-structures/algorithm question than C++, but I'm probably going to be using the STL to implement this and I'm pretty new to using it. I'm trying to implement some 2d collision detection, and I'm trying to figure out a way to efficiently examine only objects near the one I'm doing a collision calculation on. The way I want to implement this is by having each object in a bounding box and only consider the objects who's bounding box intersects the one I'm interested in. I just have no idea how to organize my objects so that I can grab only the objects I'm interested in. I have considered imposing a maximum length on objects or putting them into some sort of grid, but those don't seem like real solutions and I suspect there might be a better way. code:
|
# ? Nov 26, 2008 07:51 |
|
It's late and i'm half asleep but have you looked at geometric hashing?
|
# ? Nov 26, 2008 07:53 |
|
Contero posted:So if the object I'm considering is the box with stars, how do I organize my data in such a way that I can ignore the bottom one without having to even look at it? Ideally I'd like to logarithmically (by the number of objects in the world) grab only the ones I want. Real-Time Collision Detection by Christer Ericson has 3 full chapters about collision culling methods. Broadly speaking, you can either 1) create a bounding box hierarchy (think binary-tree), or 2) you can partition the space itself (grid, quadtrees, BSP).
|
# ? Nov 26, 2008 08:26 |
|
Avenging Dentist posted:Real-Time Collision Detection by Christer Ericson has 3 full chapters about collision culling methods. Broadly speaking, you can either 1) create a bounding box hierarchy (think binary-tree), or 2) you can partition the space itself (grid, quadtrees, BSP). I took a look around and it basically looks like it's going to be a bit more complicated that I had hoped even with simple axis-aligned bounded boxes. I might just try a simple grid or just do a detection against everything and hope it won't be too slow. I'm not going to have very many items in my scenes. If someone can explain spatial volume hierarchies in layman's terms I'd greatly appreciate it. I understand that you split the scene somewhere in the middle and build a tree, I just don't understand how to select nodes to place in the tree and in what order they are sorted.
|
# ? Nov 26, 2008 10:30 |
|
Does throw x; always create a copy of x? I'm wondering because that seems weird but I guess that's how things go.code:
code:
|
# ? Nov 26, 2008 16:17 |
|
I do believe so -- the object has to be copied somewhere safe (ie: not the stack) where it lives while the stack is unwound.
|
# ? Nov 26, 2008 16:21 |
|
Question about templated classes in C++. Why is it that, when I compile a templated class, no errors are generated by the compiler in a function I KNOW has errors unless I call that function somewhere else? Take this sample to see what I'm talking about (noting that in reality main() is in it's own cpp file that includes the templated class in question): code:
|
# ? Nov 26, 2008 17:21 |
|
Ledneh posted:Now, if I uncomment that line in main(), I get an error as expected. If I leave it commented, the project compiles completely. While it's nice that it doesn't worry about uncalled code (I guess), it makes bugfinding a pain in the rear end. Is there anything I can do to change this behavior? It sucks having to fanagle a way to call every single function in the class just to help me check for compiler errors. This is the fault of your compiler (I'm guessing Visual C++?). Templates are supposed to go through two phases of name lookup -- once when the template definition is encountered for everything in it that is not dependent on a template argument and then a second time when the template is instantiated to resolve anything that is dependent on a template argument. For compilers that do this correctly, you should get an error without having to call the function in the code you posted. For compilers which (incorrectly) put everything off to the second phase, you will only get the error when the template is instantiated via the function call. Visual C++ is one such compiler that pushes everything to phase two meaning you won't get the compiler error until you call the function. Also, use int main(), not void main(), as by standard, main must return an int.
|
# ? Nov 26, 2008 17:31 |
|
You can workaround some of it by putting as much of the nondependent code as possible in a base class (or non-memeber functions):code:
Mustach fucked around with this message at 17:48 on Nov 26, 2008 |
# ? Nov 26, 2008 17:44 |
|
That Turkey Story posted:This is the fault of your compiler (I'm guessing Visual C++?). Templates are supposed to go through two phases of name lookup -- once when the template definition is encountered for everything in it that is not dependent on a template argument and then a second time when the template is instantiated to resolve anything that is dependent on a template argument. For compilers that do this correctly, you should get an error without having to call the function in the code you posted. For compilers which (incorrectly) put everything off to the second phase, you will only get the error when the template is instantiated via the function call. Visual C++ is one such compiler that pushes everything to phase two meaning you won't get the compiler error until you call the function. Whatever compiler is being used by Sun Studio 12, actually--I don't remember. Solaris machine, anyway, but I guess if it's a compiler problem and not an inherent C++ thing I should go check. And yeah in the real code it's int main with proper parameters, I just blew that out from memory (edit) Here's a related question. Say I have another function that looks like this: code:
(edit 2) Wait, there's something that doesn't make sense about this. I know templates aren't, strictly speaking, compilable code, but the pattern to generate compilable code. Wouldn't this mean that, as soon as main() declared a specific version of the template, the compiler should know it will need to do up the whole thing like a normal class, instead of waiting until I called any given function in it? Also, would putting the template declaration AND definition in the same header file (instead of dec in header and def in a .cpp as normal) help? I can't think of why it WOULD, but I'm willing to think about it until I can get back to my machine. Ciaphas fucked around with this message at 18:29 on Nov 26, 2008 |
# ? Nov 26, 2008 17:55 |
|
Sorry for the double post, but the edit chain was getting a little convoluted. I got to my machine and tried a solution which frankly, makes no sense to me, but it definitely works. I was hoping someone could explain why. If I put something like the following line pretty much ANYWHERE in my project (or at least anywhere that #includes the template's header file) in global scope, the compiler does up the whole thing without question (and gives me all the errors I need): code:
Ciaphas fucked around with this message at 19:07 on Nov 26, 2008 |
# ? Nov 26, 2008 18:49 |
|
Ledneh posted:Besides being hopeful for an explanation as to why this gets the whole thing compiled where actually declaring an object does not, does anyone know if this will have any unintended compile-time or run-time side effects, or if it's not going to work on other compilers? That's an explicit instantiation. It just forces the template to be instantiated at that spot for those particular template arguments (including the member functions of that type). It should work on most other compilers unless they don't support explicit instantiation, though most of them nowadays do.
|
# ? Nov 26, 2008 18:58 |
|
Ah, okay, now that I know the name of that little trick I can do more looking around on my own. Thanks muchly. <line break, stupid forums> I probably learned this back in Compilers in university, but I've long since forgotten. Is there any reason the whole template doesn't get instantiated (and therefore compiled) when, in the sample code above, I declare a specific type? (the Foo<int> f; in main() above). I would guess it's for optimization's sake, but I don't know.
|
# ? Nov 26, 2008 19:06 |
|
I'm gonna try to shed some light on this from the last time I had to deal with the Sun Studio compiler's differences from the GNU compiler in handling templates. I believe the GNU compiler has a more straightforward approach to compiling templatized code than the Sun compiler. As I recall, the GNU compiler emits code for each templatized functions in each translation unit. If you'd compiled with g++ you would have gotten your compiler error without having to explicitly instantiate your template types. Your code, however, may be larger than necessary because it could contain duplicate template instantiations. More info about GNU compiler template instantiation here. You didn't get the error in your first example because the Sun compiler's default behavior is to emit code for object methods only when those methods are referenced by code that must be compiled. The Foo class's constructor was instantiated but the bar method was not. You could change this behavior to what you expect by compiling with the -template=wholeclass switch on. Or you could appreciate Sun's efficiency in saving you a tiny bit of size on your binary, not turn it on, and miss terrible errors. Either way, you will be bitter because now you know all this useless crap and Sun could've made it work like everyone expects instead of saving us a tiny bit of HD space. More info about Sun Studio 12 template instantiation here. At my job we explicitly instantiate our templatized objects because we have to support old rear end versions of the sun compiler. Explicit instantiation plays nice with Sun and GNU c++ compilers. btw, the sun c++ compiler is CC. You can man CC for some info on compiler switches and other sun shittiness. Dren fucked around with this message at 00:03 on Nov 27, 2008 |
# ? Nov 27, 2008 00:00 |
|
Dren posted:You could change this behavior to what you expect by compiling with the -template=wholeclass switch on. Or you could appreciate Sun's efficiency in saving you a tiny bit of size on your binary, not turn it on, and miss terrible errors. So, -template=wholeclass for debug builds, and skip it for release builds, then.
|
# ? Nov 27, 2008 00:05 |
|
Dren posted:I'm gonna try to shed some light on this from the last time I had to deal with the Sun Studio compiler's differences from the GNU compiler in handling templates. Boy did you peg my newfound feelings on the matter perfectly. What an annoying thing. Now I know why I never knew about this, because it really WAS never a problem before. Optimizing in a compiler is fine, but by default? Give me a break. Thanks for the great info, though
|
# ? Nov 27, 2008 00:19 |
|
Dren posted:btw, the sun c++ compiler is CC. You can man CC for some info on compiler switches and other sun shittiness. Wow, I didn't know CC was even in use anymore.
|
# ? Nov 27, 2008 01:11 |
|
I have a optimization question. I am working on a OpenGL emulator for an embedded platform, and I find myself writing many loops over things like verticies and pixels (ie large number of elements). The problem lies in the complexity of OpenGL resulting in this huge matrix of possible options on the inside of the loop. Bottom line, I originally put the selection logic inside the loop, even though all the selection inputs are invariants within the loops. This combined with function overhead is turned to be killing performance. Inlining the selection functions helped, but I found the greatest improvement was to invert the logic. Example:code:
The question is, is there a better way without sacrificing performance? Is this really a corner case where you need to whip out the crazy techniques (ie less well used, hard to maintain), like recursive macros? I tried function pointers, which greatly reduces the macro mayhem, but they are around 2-times slower because the inability to inline added significant overhead. To nip the premature optimization question in the bud, these changes yield 10 performance improvements in pixel conversion code and at least 3-4 times in the vertex processing, potentially more. These improvements are the difference between 20 fps and 60 fps. litghost fucked around with this message at 14:55 on Nov 27, 2008 |
# ? Nov 27, 2008 14:53 |
|
litghost posted:I have a optimization question. http://www.gamasutra.com/view/feature/1790/a_2d_render_base_using_policy_.php?page=1
|
# ? Nov 27, 2008 15:24 |
|
What's the easiest way to start learning C? Console or GUI apps are both fine, I'm on windows and I have cygwin if I want to use gcc (though it's sort of crap on cygwin). Any recommended sites to start reading, etc?
|
# ? Nov 27, 2008 15:38 |
|
Kelly & Pohl's A Book on C. Once you've read it cover to cover, sell it on and buy a copy of Kernighan & Ritchie's The C Programming Language. As for compilers, Visual Studio Express is free and decent.
|
# ? Nov 27, 2008 15:51 |
|
TSDK posted:Kelly & Pohl's A Book on C. Once you've read it cover to cover, sell it on and buy a copy of Kernighan & Ritchie's The C Programming Language.
|
# ? Nov 27, 2008 16:04 |
|
Bruce Eckel's Thinking in... series of books used to be okay, so you could try this one (haven't reviewed this one myself): http://mindview.net/CDs/ThinkingInC/beta3 Do you not have any public libraries kicking around near you?
|
# ? Nov 27, 2008 16:15 |
|
Your compiler should be perfectly capable of hoisting the switch statements out of the loop by itself. If this is really making a difference, something else is going on. Are you sure you're don't have optimization turned off? Why can't common_logic and more_common_logic be inlined functions? EDIT: there's no way a switch statement takes that much time. This might be a cache coherancy issue: the first form of the code can't fit both the common logic and all the different type/function specific operations into cache, so on each iteration is has to do the common code, then swap in the specific code, then swap the common code back in. In the second form, it's able to fit the entire for loop into cache. That would make your structure the "correct" thing to do. Again - check your compile settings and see if it will do this transformation itself, and if that doesn't work try your hardest to use an inlined function instead of a macro. Here's a macro idea: put the common code in common_logic.inc and more_common_logic.inc (not .h to reinforce that they're not standard header files), and then #include them at the appropriate points. Same effect as a macro - the code gets pasted in - but easier to maintain in this particular case. EDIT 2: if it IS cache coherence, this might be the place to use self-modifying code to keep the binary size down: keep one copy of "common logic" and "more common logic", and before entering the loop find out which specific code to use and arrange to load that between the two. Hey look, this is even a recommended use case. JoeNotCharles fucked around with this message at 16:22 on Nov 27, 2008 |
# ? Nov 27, 2008 16:17 |
|
TSDK posted:Bruce Eckel's Thinking in... series of books used to be okay, so you could try this one (haven't reviewed this one myself): They tend to have extremely extremely old books like "Windows 95 for Dummies."
|
# ? Nov 27, 2008 16:18 |
|
TSDK posted:Policy based design is going to be your best bet for getting a decent amount of bang for your programming buck: That still has to compile each combination into the executable, though, so he still has to worry about code bloat. (I agree that's a better approach than my lame #include suggestion; I thought he was using straight C for some reason.)
|
# ? Nov 27, 2008 16:27 |
|
Elected by Dogs posted:They tend to have extremely extremely old books like "Windows 95 for Dummies." "A Book on C" and "The C Programming Language" are also extremely old books. (I bought a well-used copy of "ABoC" in 1992 from a used book store)
|
# ? Nov 27, 2008 17:13 |
|
fritz posted:"A Book on C" and "The C Programming Language" are also extremely old books. (I bought a well-used copy of "ABoC" in 1992 from a used book store) Alright, going to library in a bit I guess. The thing is, I wanted online partially so I didn't have to retype a ton of stuff and it's easier to just select and google things.
|
# ? Nov 27, 2008 17:14 |
|
Retype what exactly? You'll get more benefit from typing out the sample & exercise problems than you ever would from copying and pasting, and I can't think of anything else you'd be retyping beyond function and struct names, which being C are likely to be about 8 characters long at a time.
|
# ? Nov 27, 2008 17:45 |
|
JoeNotCharles posted:That still has to compile each combination into the executable, though, so he still has to worry about code bloat. If you initially leave the pipelines pointing at the default case, then you can selectively pick different combinations for instantiating through templates - giving you a good way to balance speed against code size. You can even then extend the system to work with code loaded in a library (or from the assets themselves) so that you only bring in and run the code that's needed. EDIT: On the subject of code bloat, it shouldn't be assumed that inlining code will make it faster. Depending on the system, inlining (and loop unrolling) may actively hurt the performance of code. So, as with all things, the performance difference needs to be measured.
|
# ? Nov 27, 2008 19:20 |
|
Elected by Dogs posted:Alright, going to library in a bit I guess. What did you people do before the Internet? Sit there, staring at a problem, drooling incoherently and waiting for it to solve itself?
|
# ? Nov 27, 2008 20:32 |
|
Mikey-San posted:What did you people do before the Internet? Sit there, staring at a problem, drooling incoherently and waiting for it to solve itself? No internet? I was born wayyy after the internet was invented
|
# ? Nov 27, 2008 20:34 |
|
Before the internet, I did not want to be a rockstar programmer, just a plain rockstar.
|
# ? Nov 27, 2008 20:37 |
|
TSDK posted:Policy based design is going to be your best bet for getting a decent amount of bang for your programming buck: This seems to be what I did, only I did it with macros instead of templates. I was even thinking to myself that doing this is C++ would make a lot of sense, but this is only a C library. JoeNotCharles posted:Your compiler should be perfectly capable of hoisting the switch statements out of the loop by itself. If this is really making a difference, something else is going on. Are you sure you're don't have optimization turned off? Currently compiling with -Os. quote:Why can't common_logic and more_common_logic be inlined functions? I tested inlined functions, there is an improvement, but not enough. quote:EDIT: there's no way a switch statement takes that much time. I don't think it is the specific switch statements, but the switch statement leads to more functions calls and more switch statements. I did attempt to inline each level of function call, and it did improve performance, but only by a factor of 3-4. JoeNotCharles posted:That still has to compile each combination into the executable, though, so he still has to worry about code bloat. (I agree that's a better approach than my lame #include suggestion; I thought he was using straight C for some reason.) It is in straight C, for maximum compatibility. This system does not have dynamic libraries, so C++ will leak it's dependencies outward. TSDK posted:You can even then extend the system to work with code loaded in a library (or from the assets themselves) so that you only bring in and run the code that's needed. Again, this system has no dynamic library functionality, and I am not confident enough to write one. TSDK posted:On the subject of code bloat, it shouldn't be assumed that inlining code will make it faster. Depending on the system, inlining (and loop unrolling) may actively hurt the performance of code. So, as with all things, the performance difference needs to be measured. This is actually true to some point. If I compile the entire code base with -O2 it actually slower than -Os. However, in the specific case of pixel transfer and render dispatch, I measure performance improvements. I have done my best to perform test-based optimization. JoeNotCharles posted:EDIT 2: if it IS cache coherence, this might be the place to use self-modifying code to keep the binary size down: keep one copy of "common logic" and "more common logic", and before entering the loop find out which specific code to use and arrange to load that between the two. The system does not have a sophisticated profiling system, how can I detect cache coherence problems? I made a function level profiler, but that probably does not have the resolution to see such a problem. litghost fucked around with this message at 21:38 on Nov 27, 2008 |
# ? Nov 27, 2008 21:29 |
|
Elected by Dogs posted:What's the easiest way to start learning C? Console or GUI apps are both fine, I'm on windows and I have cygwin if I want to use gcc (though it's sort of crap on cygwin). Are you sure you really want to learn C? Why not jump straight to C++? Learning C first is a great way to never actually learn C++, especially if you are a casual programmer.
|
# ? Nov 28, 2008 01:40 |
|
Nippashish posted:Are you sure you really want to learn C? Why not jump straight to C++? Learning C first is a great way to never actually learn C++, especially if you are a casual programmer. Let's not have this argument again, it's the worst. Besides that, a hobbyist programmer is going to have a hell of a time ever learning all of C++, but C is pretty easy to gain a complete understanding of.
|
# ? Nov 28, 2008 01:53 |
|
Avenging Dentist posted:Let's not have this argument again, it's the worst. Besides that, a hobbyist programmer is going to have a hell of a time ever learning all of C++, but C is pretty easy to gain a complete understanding of. I think having access to classes + the STL would be a huge benefit to a novice; but yeah, we can drop it.
|
# ? Nov 28, 2008 02:24 |
|
Nippashish posted:I think having access to classes + the STL would be a huge benefit to a novice; but yeah, we can drop it. I just want to do something for fun, and possibly use it later on.
|
# ? Nov 28, 2008 02:38 |
|
|
# ? Jun 1, 2024 21:29 |
|
My experience with C is limited to `hello world` running in DOS with Turbo c++ sometime in the 90s, so I would appreciate if someone could point me in the right direction. I have a burger processor script written in php (procedural) that is constantly running in a loop. When it's busiest, it can process about 5 burgers per second (BPS), but with the overheads it puts quite a strain on the server. It's not very scalable, and, after running over a year in production I'm sure it's as optimised as it can be. I need the process to handle 50 BPS without breaking a sweat, so I figured rewriting it in a more efficient language would be a great solution. The requirements: * Runs on linux (RHEL, fedora) * Talks to mysql * Makes http request (and needs to know response header code) Will I need any special/nonstandard libraries? Anything I need to worry about if I want to be able to run it under different distros? Where do I begin?
|
# ? Nov 28, 2008 06:26 |