|
You could use OS-specific APIs, like epoll on Linux, or generally some variant of select.
|
# ? Aug 26, 2009 22:13 |
|
|
# ? Jun 7, 2024 07:53 |
|
Vanadium posted:You could use OS-specific APIs, like epoll on Linux, or generally some variant of select. I read about "select" a bit, not sure if it's what I'm thinking of . . . I guess it isn't really a socket-related question on second thought, I just want something that can check for input without freezing up a loop.
|
# ? Aug 26, 2009 22:32 |
|
HondaCivet posted:Is there a way to take in input without causing the program to hang? I'd like the program to check for input each time it runs through a loop but, of course, it waits for input instead of continuing through the loop. I'm using plain old cin (C++ here with Boost). What else could I do? 1) fork() a process to handle the network connection, using signals handlers to inform the child network process to terminate and clean up 2) use a threading library like pthreads or whatever Boost gives you, where you call [fixed]pthread_exit[/fixed} or whatever. (and the third, comedy option: 3) whatever crazy Boost poo poo there is (Is boost::asio still around? I still have nightmares from it; that poo poo was seriously my Vietnam.) ) I assume the problem you're trying to solve is "I'd like to include a little I/O on this thing so that transfer can be shut off with a text command." Any of those three solutions will work; beej has a pretty good Unix IPC guide if you want to go with 1). Dijkstracula fucked around with this message at 23:14 on Aug 26, 2009 |
# ? Aug 26, 2009 23:12 |
|
Dijkstracula posted:3) whatever crazy Boost poo poo there is (Is boost::asio still around? I still have nightmares from it; that poo poo was seriously my Vietnam.) ) HondaCivet is using Boost.Asio.
|
# ? Aug 27, 2009 01:11 |
|
HondaCivet posted:I read about "select" a bit, not sure if it's what I'm thinking of . . . I guess it isn't really a socket-related question on second thought, I just want something that can check for input without freezing up a loop. Seems to me that calling cin.peek() would work.
|
# ? Aug 27, 2009 02:57 |
|
oldkike posted:Seems to me that calling cin.peek() would work. No
|
# ? Aug 27, 2009 03:26 |
|
Avenging Dentist posted:HondaCivet is using Boost.Asio.
|
# ? Aug 27, 2009 05:28 |
|
Dijkstracula posted:Well, then, isn't this a solved problem then? Well yes, if Honda were actually a programmer by trade, as opposed to an engineer. Luckily, we work a building apart from each other.
|
# ? Aug 27, 2009 05:30 |
|
Avenging Dentist posted:Well yes, if Honda were actually a programmer by trade, as opposed to an engineer. Luckily, we work a building apart from each other. im sorry hopefully they wont let me program anymore
|
# ? Aug 27, 2009 19:42 |
|
I'm experimenting with a handle-style class with a reference counted implementation shared among all copies of the same handle. Basically it looks like this:code:
code:
|
# ? Aug 29, 2009 00:19 |
|
Just change the semantics of the clone operation to do something other than return a temporary; temporaries can't be bound to non-const (lvalue) references. How exactly you choose to do that is up to you.
|
# ? Aug 29, 2009 00:26 |
|
Is there ever a reason to pass a "const long &" to a function? I keep seeing this in my company's code and I think it's fracking retarded. One of the other programmers said that it might be more efficient to pass a reference to the long instead of passing the long itself, because that way you don't have to copy the value of the long. The explanation actually makes it seem even more stupid, because regardless of what you pass, you're still putting a 32-bit value onto the stack and it must be copied either from the value of the long or from the address of the long. Passing it by reference probably hurts performance, actually, because your function's variables are no longer likely to be close together in memory. The only possible situation I can see in which this could even so much as break even is if the long is stored in a register and the compiler/processor combined are smart enough not to clear that register when entering the function (during this process it is supposed to store the registers of the calling function, is it not?). edit: I just thought of something. Is this done in order to convince the compiler to inline certain small functions? plushpuffin fucked around with this message at 01:42 on Aug 29, 2009 |
# ? Aug 29, 2009 01:37 |
|
plushpuffin posted:Is there ever a reason to pass a "const long &" to a function? I keep seeing this in my company's code and I think it's fracking retarded. Given that on every architecture I can think of, sizeof(long) <= sizeof(void*), this is pointless. plushpuffin posted:The only possible situation I can see in which this could even so much as break even is if the long is stored in a register and the compiler/processor combined are smart enough not to clear that register when entering the function (during this process it is supposed to store the registers of the calling function, is it not?). Actually it would never* break even with a non-inline function and always break even with an inline function. While the calling conventions of functions can vary, they almost universally expect arguments to be on the stack, and to allow some stuff on the stack and others in registers would require self-modifying code (or multiple versions of each function). The only primitives that are ever worth passing as a const-ref are double and long double (ok, and maybe some weird types too, like vector types). Also, here's what you do to convince a compiler to inline a function: inline. (Or a compiler extension if you want to get pushy.) * Probably Avenging Dentist fucked around with this message at 01:44 on Aug 29, 2009 |
# ? Aug 29, 2009 01:42 |
|
Avenging Dentist posted:Also, here's what you do to convince a compiler to inline a function: inline. (Or a compiler extension if you want to get pushy.) Given that the inline keyword is actually just a hint that can be ignored, what I meant by "convince" is that it makes the compiler's job easier when deciding which functions it should automatically inline and which functions it won't. Thanks for the explanation!
|
# ? Aug 29, 2009 01:47 |
|
plushpuffin posted:Given that the inline keyword is actually just a hint that can be ignored, what I meant by "convince" is that it makes the compiler's job easier when deciding which functions it should automatically inline and which functions it won't. Giving it an obtuse hint in addition to an obvious hint isn't really going to help any sane compiler. If you want to do more than hint, you should use things like __forceinline in MSVC and __attribute__(always_inline) in GCC.
|
# ? Aug 29, 2009 01:52 |
|
Avenging Dentist posted:The only primitives that are ever worth passing as a const-ref are double and long double (ok, and maybe some weird types too, like vector types). Even still some well known compilers for some platforms will do the retarded thing and pass it (the double/vector type) in memory instead of in register even if the ABI allows for it.
|
# ? Aug 29, 2009 02:04 |
|
ehnus posted:Even still some well known compilers for some platforms will do the retarded thing and pass it (the double/vector type) in memory instead of in register even if the ABI allows for it. Well registers technically have no address.
|
# ? Aug 29, 2009 02:07 |
|
Avenging Dentist posted:Giving it an obtuse hint in addition to an obvious hint isn't really going to help any sane compiler. If you want to do more than hint, you should use things like __forceinline in MSVC and __attribute__(always_inline) in GCC. The __attribute__(always_inline) is also used in Clang
|
# ? Aug 29, 2009 02:08 |
|
king_kilr posted:The __attribute__(always_inline) is also used in Clang Yes but clang isn't a C++ compiler.
|
# ? Aug 29, 2009 02:12 |
|
Avenging Dentist posted:Well registers technically have no address. Well, yeah, but I meant that there would be no performance advantage of passing a const reference over passing one of those primitive types by value because of the forced memory access
|
# ? Aug 29, 2009 02:18 |
|
ehnus posted:Well, yeah, but I meant that there would be no performance advantage of passing a const reference over passing one of those primitive types by value because of the forced memory access What if you need to save 4 bytes of memory? What then, mister?
|
# ? Aug 29, 2009 02:19 |
|
Avenging Dentist posted:What if you need to save 4 bytes of memory? What then, mister? I'd shorten my variable names.
|
# ? Aug 29, 2009 02:21 |
|
plushpuffin posted:Is there ever a reason to pass a "const long &" to a function? I keep seeing this in my company's code and I think it's fracking retarded. You might want to take the address of the long and have it be the address of the passed-in variable.
|
# ? Aug 29, 2009 08:35 |
|
Avenging Dentist posted:Yes but clang isn't a C++ compiler. Only because you are too lazy
|
# ? Aug 29, 2009 17:28 |
|
I'm trying to make sense of some source code for a splay tree as I'm going to have to modify it slightly for use in a Ruby library. I'm pretty comfortable with the concept of splay trees especially using bottom-up splays (i.e. BST style search, then splay), but this code uses a top-down approach. Firstly, is a top-down approach (splaying from the root rather than running to the bottom first) actually worth while in terms of performance gains over the easier to understand bottom-up approach? Secondly, the code. This section I am particularly confused about : code:
Maybe someone who's worked with this technique before can give me an idea?
|
# ? Aug 31, 2009 16:22 |
|
There are a lot of undocumented invariants in that function; an important method for puzzling them out is to look at final code like that and see how it pieces things back together. Doing so tells you that:
The crucial invariants are:
If you look over the entire top-down splay with those invariants in mind, everything should come together. rjmccall fucked around with this message at 18:39 on Aug 31, 2009 |
# ? Aug 31, 2009 18:20 |
|
code:
|
# ? Sep 1, 2009 01:36 |
|
Is there a C++ library out there that can help with "graphical" console apps? Basically I just need to output to the console, clear my output and replace it with new output, and change colors -- nothing too fancy. I took a quick look at ncurses and it seems a bit of a bear. Is there a better alternative?
|
# ? Sep 1, 2009 01:57 |
|
ultra-inquisitor posted:Is this safe? I can't think why it wouldn't be but C++ is always surprising me. Well, it is obviously broken when sizeof(float) < sizeof(void*) (which is true on any 64-bit platform that I know of), and C++ doesn't guarantee the absence of padding between adjacent struct members — but if you're specifically targeting a platform with an ABI that lays out that struct like you want, then it's certainly safe. That said, you should (1) probably guard it in platform-specific #ifs or, better yet, (2) just make it float f[3], since presumably you never want two floats and a pointer. Or just heap-allocate the vector case, which is presumably much less common than the other two.
|
# ? Sep 1, 2009 02:30 |
|
rjmccall posted:C++ doesn't guarantee the absence of padding between adjacent struct members quote:That said, you should (1) probably guard it in platform-specific #ifs or, better yet, (2) just make it float f[3], since presumably you never want two floats and a pointer. Or just heap-allocate the vector case, which is presumably much less common than the other two. Ultimately it's all a speed issue and only profiling will tell for sure what the best method is, but I'm just putting my thoughts out in case I'm doing something obviously stupid.
|
# ? Sep 1, 2009 02:55 |
|
ultra-inquisitor posted:The issue is that I want to keep the structure at 16 bytes, while allowing it to hold ints/floats/pointers/vector3s. Ummmmm....
|
# ? Sep 1, 2009 03:04 |
|
Dijkstracula posted:3) whatever crazy Boost poo poo there is (Is boost::asio still around? I still have nightmares from it; that poo poo was seriously my Vietnam.) ) Don't let people scare you off from boost::asio, it's actually really easy to use and has dozens of example programs that you can probably template your needs around. You might want to look at this specific one which use posix::stream_descriptor's to read from stdin. I'm using this right now at work to aggregate and sort through a ton of real time logging data from files. The only real gotcha to boost::asio I found when dealing with formatted strings is the read methods are sort of misleadingly named. "read_until" methods that take a regex only guarantee that the returned buffer would returned "true" if checked for the regular expression. So if you "read until" newline, you'll get a newline in there somewhere. There is no guarantee that you'll end with a newline, or have only a single newline in your buffer.
|
# ? Sep 1, 2009 03:08 |
|
Avenging Dentist posted:Ummmmm....
|
# ? Sep 1, 2009 03:10 |
|
Does clang have a hope of making template errors more readable? Or is that problem basically intractable. Boost.fusion reminds me of that line from The Usual Suspects. "How do you shoot the devil in the back? What if you miss?" When you get it right it's miraculous, but one little mistake and gcc is all code:
So given a transform view, what's the slick way to put its contents into a boost.array? The adaptation from array into fusion is great, but the other direction isn't jumping out at me. Could I make a no-op view of the destination array and then do a view-to-view assignment? But there must be something cleaner. Fecotourist fucked around with this message at 06:42 on Sep 2, 2009 |
# ? Sep 2, 2009 05:21 |
|
I don't know how Clang does on template error messages, but one of the things I've heard, both from Brett Cannon on compiling CPython and from the Ars Technica review of Clang integration in XCode is that the errors are lightyears better.
|
# ? Sep 2, 2009 15:51 |
|
king_kilr posted:I don't know how Clang does on template error messages, but one of the things I've heard, both from Brett Cannon on compiling CPython and from the Ars Technica review of Clang integration in XCode is that the errors are lightyears better. The examples in the Ars review were brilliant. Highlight the exact token it choked on in the editor view? Yes, please.
|
# ? Sep 2, 2009 16:01 |
|
Well, for one thing, clang tries to use the shorthand you (the programmer) used for your templates. So you'll see std::string (std::basic_string<char>) if you gently caress something up with a string.
|
# ? Sep 2, 2009 17:53 |
|
Avenging Dentist posted:Now you've gone and done it. I'm just going to have to recommend Boost.Parameter. I came across another approach that is a little less intimidating than boost.parameter and probably fits most realistic use cases: http://www.nabble.com/-fusion--parameter--a-solution-for-named-parameters---parameter-packs-using-fusion-maps-td18963630.html Is David Abrahams always such a bitch? Here's more from him: http://lists.boost.org/boost-users/2007/06/28487.php
|
# ? Sep 2, 2009 18:14 |
|
How is he being a bitch in either of those?
|
# ? Sep 2, 2009 19:05 |
|
|
# ? Jun 7, 2024 07:53 |
|
Chuu posted:Is there a C++ library out there that can help with "graphical" console apps? Basically I just need to output to the console, clear my output and replace it with new output, and change colors -- nothing too fancy. NCurses is pretty easy to use.
|
# ? Sep 2, 2009 19:12 |