|
DoctorTristan posted:
You're creating a temporary ParamPointerPair object, pointing to the new EA2Skeleton object, and then pushing a copy of that object into the list. So you now have at least two objects of type ParamPointerPair pointing to the same skeleton. As that temporary object goes out of scope, the destructor deletes the instance of EA2Skeleton, returning the memory to the free memory pool, ready to be allocated on the next addParam. EDIT: One more thing - typedef's are supposed to be there to make your code more concise and readable, not to give really long, unhelpful names to things. TSDK fucked around with this message at 18:26 on Jun 22, 2009 |
# ? Jun 22, 2009 18:23 |
|
|
# ? May 18, 2024 06:56 |
|
Thanks for spotting that. I'm pretty sure my C++ book warned about that very thing, but the lesson didn't sink in I guess. So I guess the simplest solution would be to have the container class clean up the heap memory on destruction, rather than ParamPointerPair? (once I'm done with the ParamPointerPair objects I'm done with the container) Will write better typedefs next time, promise.
|
# ? Jun 22, 2009 20:11 |
|
DoctorTristan posted:So I guess the simplest solution would be to have the container class clean up the heap memory on destruction, rather than ParamPointerPair? (once I'm done with the ParamPointerPair objects I'm done with the container) Your current code breaks that rule of thumb by creating objects in one place (EA2ParameterAndSkeletonArray) and deleting them in another (ParamAndPointerToSkel) and that's exactly what has caused problems. Note that you could also logically fix the problem by moving the new totally over into ParamAndPointerToSkel and give the class full deep-copy semantics with implementations of a copy constructor and assignment constructor (again restoring the above rule of thumb). But this wouldn't be very optimal, so the first fix is preferable. TSDK fucked around with this message at 22:30 on Jun 22, 2009 |
# ? Jun 22, 2009 22:23 |
|
I have a really cryptic question. I have a plugin for a source dedicated server (for counter strike source specifically) and I am trying to do an auto update feature for the plugin. Now, I can identify the version I have and the latest version, that was easy. The problem is downloading the new file. I got curl and am using it correctly, I have a separate test project that just downloads the file. The problem is, whenever I try and use the function within the server plugin, I get error # 27, which is "A memory allocation request failed. This is serious badness and things are severely screwed up if this ever occurs". Sweet! Love that error, anyone have an ideas on wtf? edit: you probably need the code lol, it's just a curl example ripped right from the website so I knew it worked. code:
Sweeper fucked around with this message at 03:36 on Jun 23, 2009 |
# ? Jun 23, 2009 02:22 |
|
code:
Also move the fopen() out of the callback so you can do proper error checking, it's possible that returning -1 from CURLOPT_WRITEFUNCTION is confusing it. Standish fucked around with this message at 12:38 on Jun 23, 2009 |
# ? Jun 23, 2009 12:31 |
|
Currently I have this code that executes and stalls until a character is entered and then 2 seconds from that moment a handler will be triggered. However what I'm aiming for is the ability to interrupt getchar() or fgets() [things like loops are interrupted fine] and fire off the handler after the 2 seconds the signal was called.code:
Any help is much appreciated, if what I'm aiming for is impossible then that's cool too . Thanks in advance! Rampager fucked around with this message at 17:00 on Jun 23, 2009 |
# ? Jun 23, 2009 13:36 |
|
ITIMER_VIRTUAL only increments while the process is actually running, not while it's blocked on io, try ITIMER_REAL instead. Also printf() isn't safe to call inside a signal handler (and neither are most library functions in general, see man(7) signal).
|
# ? Jun 23, 2009 14:46 |
|
This works well, thanks! I'll have to check out signal more indepth now.
|
# ? Jun 23, 2009 17:32 |
|
I don't seem to understand something fundamental about boost::call_traits.code:
error: no matching function for call to 'foo(int)' — foo (5) Why shouldn't this work?
|
# ? Jun 23, 2009 20:37 |
|
Lexical Unit posted:Why shouldn't this work? How would the compiler deduce the type of T? (It wouldn't.)
|
# ? Jun 23, 2009 20:46 |
|
I kept looking at example 4 without getting it.
|
# ? Jun 23, 2009 20:50 |
|
Standish posted:
edit: So it opens the file now, but I still get error #27 here is the code, again it works in it's own program, but not in the loaded .dll, did I do the return incorrectly for the writefunction? code:
Usually if it's successful it does one of these: code:
Sweeper fucked around with this message at 00:03 on Jun 24, 2009 |
# ? Jun 23, 2009 21:31 |
|
I'm trying to write a program that reads an ASCII file and writes the same data to a binary file. Every time I run the program I'm getting a segmentation error, which I understand occurs when a pointer goes out of scope. Thing is, I can't figure out why this is happening. Here's the relevant bit of code: code:
I guess I could change the int temp to an character array and read all of my source file to that, then write everything to the binary file, but I am really curious to know why this doesn't work.
|
# ? Jun 24, 2009 21:33 |
|
Adahn the nameless posted:I'm trying to write a program that reads an ASCII file and writes the same data to a binary file. Every time I run the program I'm getting a segmentation error, which I understand occurs when a pointer goes out of scope. What is source? What is designation? Are they opened correctly? Are you doing proper error checking when you open the streams/file descriptors? Have you run this through a debugger to pinpoint the line where it's crashing? edit: ah, didn't catch the missing addressof operator. Dijkstracula fucked around with this message at 21:51 on Jun 24, 2009 |
# ? Jun 24, 2009 21:46 |
|
Adahn the nameless posted:I guess I could change the int temp to an character array and read all of my source file to that, then write everything to the binary file, but I am really curious to know why this doesn't work. You are trying to turn a number (e.g. 10) into a pointer. Dereferencing the memory address 0x0000 000A (10) is almost certainly going to fail. You want to reinterpret_cast<char*>(&temp). All that is assuming that you want to do the following (which I doubt): code:
Avenging Dentist fucked around with this message at 21:52 on Jun 24, 2009 |
# ? Jun 24, 2009 21:47 |
|
Avenging Dentist posted:Yes, through non-standard extensions supported in gcc and MSVC (stolen verbatim from one of my projects): Sorry to dredge this up from April (pg 95), but if you're returning these things by value, g++ at least stumbles when it's optimization time (either -O2 or -O3). I have some simple expression template code which lets the user build a pipeline of the form Op1<Op2<Op3> > > and applies it over a huge set of 4-float objects. Without the union trick it runs just as fast as handwritten inline code (all functions are inline, so there's no overhead return-by-value after optimization), but with it there's a repeatable 15% slowdown for my current test case and even simplified variations of it. I'm not even using the array part of the union. The speed difference is between states of this #if: code:
It turns out that, at the moment at least, indexed access to components is by indices known at compile time, so specialized get<int>(void) member functions seems to get the best of both worlds. But what I really want is the best of all 3 worlds. Is there some obscure syntax that might help?
|
# ? Jun 24, 2009 22:01 |
|
Woohoo new errors! Now when I try and set the url it gives me back error 27, but when I do the perform it's error #3! The original problem was caused by using a bad libray... lame. So I got a new one, and this one is now being lame.code:
result = curl_easy_setopt(curl, CURLOPT_URL, *url); Msg("Error [%d] - %s\n", result, curl_easy_strerror(result)); prints out error 27, Out of Memory. This: result=curl_easy_perform(curl); Msg("Error [%d] - %s\n", result, curl_easy_strerror(result)); prints out Error 3, malformed URL.
|
# ? Jun 25, 2009 01:11 |
|
First, try to reduce your code to a minimal test case that shows the failure, preferably as a complete program. Otherwise, people can't really compile or test your code so unless you did something really obviously wrong, you won't get any help.
|
# ? Jun 25, 2009 01:31 |
|
quote != edit
|
# ? Jun 25, 2009 02:42 |
|
Here's a cool feature in C++0x that I wasn't aware of, and am not actually 100% sure how to use it yet: axioms. It looks like they're used to help the compiler make optimizations and could very well make expression templates obsolete as algebraic optimizers. From the C++0x draft standard: code:
|
# ? Jun 25, 2009 04:53 |
|
Avenging Dentist posted:You are trying to turn a number (e.g. 10) into a pointer. Dereferencing the memory address 0x0000 000A (10) is almost certainly going to fail. You want to reinterpret_cast<char*>(&temp). That did it, thanks. I have the program working in a sort of way. I don't really get your joke though. Cause I'm dumb. What I did was read from a list of numbers and write those same numbers to a binary file.
|
# ? Jun 25, 2009 06:36 |
|
Avenging Dentist posted:Here's a cool feature in C++0x that I wasn't aware of, and am not actually 100% sure how to use it yet: axioms. It looks like they're used to help the compiler make optimizations and could very well make expression templates obsolete as algebraic optimizers. Causal assert()? I'm all for ways to tell the compiler about invariants that it can assume to be true when it's optimizing. For example, "if condition A is true, then cheap computation B is equivalent to expensive C". If the compiler is instantiating a template and can deduce that A is always true in this context, that could be a big win. This is probably just daydreaming but I can imagine implementing something like interval arithmetic, where you make guarantees about the range of a numerical function's output, and the compiler is prodded to pick the most efficient approximation that's accurate enough. Like in y=exp(sin(x)), you know that the argument of exp() is between -1 and 1, so maybe use a cheap approximation.
|
# ? Jun 25, 2009 07:15 |
|
Fecotourist posted:Causal assert()? It's the opposite of an assert, basically. It says to the compiler, "don't bother checking this, it's always true". Hence the name "axiom".
|
# ? Jun 25, 2009 07:20 |
|
Avenging Dentist posted:It's the opposite of an assert, basically. It says to the compiler, "don't bother checking this, it's always true". Hence the name "axiom". "Opposite" only in the sense that it happens before, rather than after. More precisely "assert(), but causal". Either way, you're making a claim that something is true, the only difference is whether the compiler verifies its truth after the computation or does the computation with that knowledge in mind up front. If you as a programmer make a mistake and assert() something that isn't always true, the mode of failure is unexpected core dumps, usually an easy investigation. If you claim as an axiom something that isn't always true (like "F commutes with G" when it actually doesn't), have fun tracking that bug down. Anyway, what I get out of expression templates is the elimination of temporaries and unnecessary memory traffic, and I can't see that axiom obsoletes them in that sense.
|
# ? Jun 25, 2009 08:31 |
|
I thought axioms were the method of creating concepts? Just as you've shown, they allowed you to formalize, in code, the self-documenting concepts of Semigroup and Monoid. Or is there another way you'd write new (or simply not standard/compiler provided) concepts in C++0x?
|
# ? Jun 25, 2009 13:30 |
|
Fecotourist posted:Anyway, what I get out of expression templates is the elimination of temporaries and unnecessary memory traffic, and I can't see that axiom obsoletes them in that sense. Using expression templates for elimination of temporaries has already been rendered unnecessary without concepts, thanks to rvalue references. Lexical Unit posted:Or is there another way you'd write new (or simply not standard/compiler provided) concepts in C++0x? For most concepts, you just write out the associated functions. Axioms are meant to build on that.
|
# ? Jun 25, 2009 17:02 |
|
Avenging Dentist posted:Using expression templates for elimination of temporaries has already been rendered unnecessary without concepts, thanks to rvalue references. I understand how rvalue references can eliminate some copies by enabling move constructors, but does it really allow loop fusion between separate calls to operators? For example, A B and C are array-like objects in y=(A+B)*C. If you define the math operators without expression templates, the compiler does A+B in one pass to fill a temporary, then another pass to multiply the temporary with C to fill y. Do rvalue references let the compiler see through the logic and do it all at once? Ok, you can have the operators all return lazy-evaluated ranges, operator= is the only one to actually iterate through elements, but you can do all that right now.
|
# ? Jun 25, 2009 18:09 |
|
Fecotourist posted:I understand how rvalue references can eliminate some copies by enabling move constructors, but does it really allow loop fusion between separate calls to operators? You are conflating two separate topics. I was specifically referring to elimination of temporaries using expression templates. Expression templates could potentially be smarter, but rvalue references eliminate temporaries except when both of the operands in your expression tree are leaves (assuming you don't std::move one or more of the leaves). In your example, the end result would be one temporary that gets moved into y. You could have multiple temporaries, which I suppose would benefit from expression templates, or you could just rely on your compiler being sufficiently smart as to take advantage of axioms to clean up the expression tree. Now if only there was an axiom that would allow operator && to short-circuit... Avenging Dentist fucked around with this message at 18:34 on Jun 25, 2009 |
# ? Jun 25, 2009 18:21 |
|
Avenging Dentist posted:In your example, the end result would be one temporary that gets moved into y. You could have multiple temporaries, which I suppose would benefit from expression templates, or you could just rely on your compiler being sufficiently smart as to take advantage of axioms to clean up the expression tree. My point was that even with a single moved temporary, there's an extraneous loop that I don't see axiom/concept/rvalue-references helping to eliminate. There's one big loop that creates t=(A+B), and another big loop to do t*=C, then the (trivial, one pointer assignment) move constructor y=t, right? If I need those loops fused (which is 90% of what I need from ET), then I pretty much need to do everything under C++0x that I need to do now.
|
# ? Jun 25, 2009 20:00 |
|
Fecotourist posted:My point was that even with a single moved temporary, there's an extraneous loop that I don't see axiom/concept/rvalue-references helping to eliminate. Yes, and I wasn't talking about loop fusion at all. I was simply talking about temporaries.
|
# ? Jun 25, 2009 20:33 |
|
Paging That Turkey Story to the C++ thread... Is the following legal in C++0x? The gcc-snapshot package rejects it, but gcc 4.4's initializer list implementation is buggy as gently caress. code:
pre:new-expression: ::opt new new-placementopt new-type-id new-initializeropt ::opt new new-placementopt ( type-id ) new-initializeropt new-placement: ( expression-list ) new-type-id: type-specifier-seq new-declaratoropt new-declarator: ptr-operator new-declaratoropt noptr-new-declarator noptr-new-declarator: [ expression ] noptr-new-declarator [ constant-expression ] new-initializer: ( expression-listopt ) braced-init-list ... 15 A new-expression that creates an object of type T initializes that object as follows: — If the new-initializer is omitted, the object is default-initialized (8.5); if no initialization is performed, the object has inteterminate value. — Otherwise, the new-initializer is interpreted according to the initialization rules of 8.5 for direct-initialization.
|
# ? Jun 26, 2009 05:06 |
|
I think you're correct but I'm probably just as unfamiliar with this area of standardization as you are. I'm almost positive that one of the use-cases for new with initializers was for array types, but I may be wrong on that. The standard certainly seems to make it sound like it is allowed. Does new with initializer lists work with structs in 4.4?
|
# ? Jun 26, 2009 05:57 |
|
That Turkey Story posted:Does new with initializer lists work with structs in 4.4? Only if you have a constructor that takes an std::initializer_list<T>. The grammar seems to suggest that new int{4} and new int[3]{1, 2, 3} are both legit, and nothing in 5.3.4 (New) or 8.5 (Initializers) suggests that either are invalid. The 2003 standard certainly invalidates them both, though (for different reasons). I ask because I'm giving a talk to my department on C++0x tomorrow and I just realized today that my example doesn't compile in 4.4. EDIT: lol I managed to make it crash with an internal compiler error by trying std::string{"foo"}; Guess I'll compile 4.4 or the nightly or whatever tomorrow and start submitting bug reports. Avenging Dentist fucked around with this message at 06:23 on Jun 26, 2009 |
# ? Jun 26, 2009 06:16 |
|
What could cause a call to close() to block (seemingly) indefinitely? The file descriptor was created with pipe().
|
# ? Jun 29, 2009 06:34 |
|
This might be a crazy idea, but here goes. I've got a VS 2008 solution with fourteen or so C++ projects in it, all of which get statically linked together into a single executable. Each of the fourteen projects has a string table. The VS string table editor is not aware of other projects in the solution and will happily let you create duplicate IDs that are only found when the resources are compiled together (the final .exe project includes the other projects' resources into its own). This late-notice collision is not cool, and our resource IDs are fragmented enough that it happens pretty much every time one of the developers adds a new string to any project. One of my teammates and I got to talking today, and we wondered if there is a sane way to generate string ID numbers at compile time rather than design time; that is, convince the resource compiler - or some prebuild process - to collate the existing string tables and reassign non-colliding IDs once all the strings are known. This would result in string IDs [potentially] changing in each endstate image, but that shouldn't be a problem...right? There are probably dozens of reasons that make this a terrible idea. For one thing, the VS string table editor wouldn't know what the gently caress, which probably will make localization difficult - I don't know the exact localization process that our company uses, only that we contract out to have it done. What I'm looking for is: a) reasons this is stupid so I can focus my unused energy somewhere more useful b) ways this might work at all, just so I can play around with it It probably won't end up being valuable to anyone, but I think it's an interesting thought exercise and I'm sort of underscheduled this month
|
# ? Jun 30, 2009 02:26 |
|
I don't know poo poo about Visual Studio, but why not just make an internal registration database keyed to the IDs that each developer drops their IDs into. Hell, you could even just do it as a wiki page.
|
# ? Jun 30, 2009 02:32 |
|
quadreb posted:I don't know poo poo about Visual Studio, but why not just make an internal registration database keyed to the IDs that each developer drops their IDs into. Hell, you could even just do it as a wiki page. I'm really not sure what you're suggesting with this...
|
# ? Jun 30, 2009 02:48 |
|
I'm suggesting a process to self-regulate the assignment of new ID numbers.
|
# ? Jun 30, 2009 02:54 |
|
quadreb posted:I'm suggesting a process to self-regulate the assignment of new ID numbers. VS already autoassigns the IDs numbers, which is the problem because it does so stupidly I'm looking for a new process to autoassign at a different point in the cycle. e: Even if the string table designer did understand multiple projects in a solution and could autogenerate IDs that don't conflict within a single solution, that doesn't help when multiple instances of VS (many developers) are generating the same IDs. e2: I should mention that resource IDs are two-byte unsigned integers. csammis fucked around with this message at 14:24 on Jun 30, 2009 |
# ? Jun 30, 2009 03:49 |
|
|
# ? May 18, 2024 06:56 |
|
csammis posted:VS already autoassigns the IDs numbers, which is the problem because it does so stupidly I'm looking for a new process to autoassign at a different point in the cycle. Manually fix the IDs once, never worry about it again (for a while anyway)? If it's anything like resource IDs, it's sequential. For example: code:
|
# ? Jun 30, 2009 03:54 |