|
Zerf posted:Yay for working with undefined behavior while making real-time systems! But games aren't real-time systems and I don't think I'd want to use C++ for real-time computing anyway???
|
# ? May 13, 2010 07:48 |
|
|
# ? Jun 8, 2024 16:58 |
|
Avenging Dentist posted:But games aren't real-time systems and I don't think I'd want to use C++ for real-time computing anyway??? Entirely depends on how you define real-time systems. Try googling it, you'd be surprised. If you have a hard target of a framerate of 30 fps, it means you have a timeslice of 33 ms to work with each frame. In my book, that's a real-time constraint.
|
# ? May 13, 2010 08:07 |
|
Ok, let's say you're right that games have a "real-time constraint" (they don't; it's a guideline, no one is going to recall a game because the framerate stutters once an hour for some users). Then game programmers are all complete idiots for using a language ill-suited to real-time computing in the first place. More to the point: the STL isn't really well-suited to game development anyway (at least not "AAA" games), so the problems with vectors run considerably deeper than "clear() has undefined behavior". Granted, this is somewhat better in C++0x with slightly less stupid allocator support.
|
# ? May 13, 2010 18:53 |
|
More on why STL can suck for games here http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html Summary: EA ended up writing their own STL-like collection of data-structures and algorithms for in-house use.
|
# ? May 13, 2010 19:15 |
|
I was really pleasantly surprised when I first saw that. It's nice to see game developers taking advantage of the opportunity to present their issues rather than writing their in-house replacement and bitching about the STL but never trying to fix it. (That said, I basically hate the STL.)
|
# ? May 13, 2010 19:27 |
|
Zakalwe posted:More on why STL can suck for games here http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html An Trolltech followed suited for Qt for pretty much the same reasons.
|
# ? May 14, 2010 03:04 |
|
MrMoo posted:An Trolltech followed suited for Qt for pretty much the same reasons. No they didn't? IIRC, Trolltech rolled their own because they for some reason just liked Java iterators more than C++ ones.
|
# ? May 14, 2010 08:21 |
|
floWenoL posted:No they didn't? IIRC, Trolltech rolled their own because they for some reason just liked Java iterators more than C++ ones. They have a list of reasons, but memory was the main one I saw, Trolltech posted:Whereas STL's containers are optimized for raw speed, Qt's container classes have been carefully designed to provide convenience, minimal memory usage, and minimal code expansion. For example, Qt's containers are implicitly shared, meaning that they can be passed around as values without forcing a deep copy to occur. Also, sizeof(QXxx) == sizeof(void *) for any Qt container, and no memory allocation takes place for empty containers. http://doc.trolltech.com/4.0/qt4-tulip.html
|
# ? May 14, 2010 09:53 |
|
Symbian also had some kind of collection of data structure classes that was completely different from STL. It was disgusting, just like everything else about Symbian.
|
# ? May 14, 2010 15:32 |
|
Backing up a bit,UraniumAnchor posted:Const reference if your function isn't going to modify, pointer if it will. I discussed this with another mate of mine and he said his rule is "use pointers if there's any chance the parameter could be NULL (either coming in or going out) and use references otherwise, and use const as appropriate." Sounds reasonable enough to me. On another question that I think the answer to is going to make me feel completely retarded: is it C++ standard behavior to do nothing on a delete of a NULL/0 pointer, rather than coredump/throw an exception, or is that compiler dependent? And if it's the former, why the hell have I been doing things like if (ptr) delete ptr; all these years?
|
# ? May 14, 2010 17:32 |
|
Ledneh posted:is it C++ standard behavior to do nothing on a delete of a NULL/0 pointer Ledneh posted:why the hell have I been doing things like if (ptr) delete ptr; all these years?
|
# ? May 14, 2010 17:48 |
|
Son of a bitch
|
# ? May 14, 2010 18:00 |
|
Plorkyeran posted:
|
# ? May 14, 2010 18:13 |
|
So I've moved on from using Dev-C++ in class for simple one-file projects, and I'm attempting a larger project for my first time, using Visual C++ 2008. (Express Edition, in case it matters) I've run into a bunch of problems, but so far I've managed to find solutions on Google. Until now. I'm trying to use the library OpenCV for accessing my webcam, but I get errors like: error C3862: 'cvRound': cannot compile an unmanaged function with /clr:pure or /clr:safe and error C3645: 'cvRound' : __clrcall cannot be used on functions compiled to native code which Google tells me is caused by trying to compile it as managed code, when it can't be compiled to manged code because it uses inline assembly. At least, I think that is the problem. Unfortunately, I can't find any way to change it to unmanaged code. The project was started as a Windows Forms Application, which apparently makes it automatically managed, and I've heard that making it a Win32 project instead will fix the problem, but that would also mean redoing all my forms (I think? I'm not to sure about the redoing forms part.) Can anyone help me please? I can post code if it would help, but I'm note sure what code I should post.
|
# ? May 14, 2010 22:18 |
|
C++ doesn't support WinForms. You might be able to keep your forms, but I doubt it.
|
# ? May 14, 2010 22:45 |
|
drat. Well, I guess I can manage without the forms, but its still going to suck redoing everything. I guess I'll know better next time.
|
# ? May 14, 2010 22:53 |
|
In theory, it's possible to do what you want, but it's not easy and I wouldn't recommend it anyway, since C++/CLI is kinda crap to be honest.
|
# ? May 14, 2010 23:17 |
|
Okay so I have to read from a file, malloc a new structure and write the data into that new structure. That's the description but I'm having a bit of trouble figuring out how to actually do that. Little hits please?
|
# ? May 17, 2010 03:51 |
|
washow posted:Okay so I have to read from a file, malloc a new structure and write the data into that new structure. Describe the struct and the file format. Does the struct have an array holding the entire file contents? Or are you reading sections of the file and storing them in individual fields in the struct? Is it a binary file with the needed data at fixed offsets, or is it text that needs to be parsed? mr_jim fucked around with this message at 04:16 on May 17, 2010 |
# ? May 17, 2010 04:12 |
|
washow posted:Okay so I have to read from a file, malloc a new structure and write the data into that new structure. Do you know how to do any of those individual steps? If you do it should be extremely easy. If not, write a basic program to learn how to do that step like making a small program that reads something from a file and prints it out immediately.
|
# ? May 17, 2010 05:37 |
|
mr_jim posted:Describe the struct and the file format. Does the struct have an array holding the entire file contents? Or are you reading sections of the file and storing them in individual fields in the struct? Is it a binary file with the needed data at fixed offsets, or is it text that needs to be parsed? Just a txt file. I'm prompting 3 different things, simple int int char and storing them in an array of structure. After sorting and other small stuff, I transfer all that stuff to a txt file. Then I dynamically allocate an array of structures based on the effective size and populate that said array with the records from the txt file. Last part is where I'm stuck at. Oh and something happens during the sorting part and whatever happens to be on top becomes gibberish. The rest is fine however I'm looking at fread and fwrite and stuff on cplusplus.com but still going at this moment
|
# ? May 17, 2010 05:43 |
|
If it's just a simple text file you can use fscanf. Example:code:
code:
|
# ? May 17, 2010 05:56 |
|
If it's text based you don't want fread/fwrite anyway, that's for binary data. You probably want fscanf for now. If it's int/int/char then you can probably use: code:
Note: This is not the best way to deal with it, but it'll probably work well enough for now. efb you bastard
|
# ? May 17, 2010 05:57 |
|
I'm just refreshing my C++ knowledge after a few months in Java/scripting languages, and I'm running into a bit of trouble. I think it has something to do with a destructor, but I'm not sure what exactly. My program runs fine in debug mode until I try to delete one of my tableEntry objects, at which my program receives a SIGTRAP signal.code:
Full Code is available at http://codepad.org/NVslQUpP I'm using MinGW tools. I've been trying to deal with this for a good few hours to no avail. Colonel Taint fucked around with this message at 06:15 on May 17, 2010 |
# ? May 17, 2010 05:58 |
|
Ahh fscanf. I was looking at a wrong thing then. Thanks goons!
|
# ? May 17, 2010 06:13 |
|
SintaxError posted:I'm just refreshing my C++ knowledge after a few months in Java/scripting languages, and I'm running into a bit of trouble. I think it has something to do with a destructor, but I'm not sure what exactly. My program runs fine in debug mode until I try to delete one of my tableEntry objects, at which my program receives a SIGTRAP signal. 0) Unless you're doing some class homework with restrictions on legit language functionality, you should not be working with strings this way in a C++ program. Use a string class, like std::string (or std::wstring, or whatever) 1) When you're copying strings, you're not including space for zero termination in the allocation. 2) Whatever you allocate with new[] you should delete with delete[], not delete.
|
# ? May 17, 2010 07:42 |
|
So I want to teach myself C - could anyone suggest what the best book to get would be? Basically I know a little bit about programming from the Pascal days at school and from messing around in Python so don't really need to go through the Hello World/If-Then Loops style tutorials. On the other hand I need something which will explain topics such as pointers as if I were an absolute beginner since I've never been exposed to them.
|
# ? May 17, 2010 10:13 |
|
User Friendly posted:So I want to teach myself C - could anyone suggest what the best book to get would be?
|
# ? May 17, 2010 11:56 |
|
OddObserver posted:Problems I can see from quick read: Ah, thank you. That fixed it. The only reason I'm working with strings like that is because I'm using strtok to get the strings from a buffer. This program is meant to be as fast as possible, so I want to be avoid making copies of strings that I don't really need copies of. As such, I've actually modified it a bit to use a const char* to point directly into the buffer to the word. code:
|
# ? May 17, 2010 16:28 |
|
SintaxError posted:This program is meant to be as fast as possible, so I want to be avoid making copies of strings that I don't really need copies of. As such, I've actually modified it a bit to use a const char* to point directly into the buffer to the word.
|
# ? May 17, 2010 17:57 |
|
Uh really? I was just doing this as an exercise as part of this programming challenge http://cplus.about.com/od/programmingchallenges/a/challenge9.htm Given, it's been over for years, but I see no reason not to write it in the most optimized way I can think of as an exercise. Really I normally would write code in the most readable/maintainable way, but the point of the contest was to make the program as fast as possible, and I see no reason why I couldn't/shouldn't do it with no copies given the circumstances. Furthermore Me posted:The app is small enough that it's manageable, and I know for a fact that the buffer will be in memory for the duration of the program and will not be used for any other purposes. So this works well enough for my needs. I really see no reason not to do it like this in such a small app. Making a copy of each of 50000 strings just seems like a huge waste of time and memory. Colonel Taint fucked around with this message at 18:36 on May 17, 2010 |
# ? May 17, 2010 18:25 |
|
1) That's a retarded exercise, and a retarded website. 2) You optimize after you have a correct version of your code. I can make a project arbitrarily fast if I'm not constrained by correctness.
|
# ? May 17, 2010 18:33 |
|
All 'retardedness' aside, I guess I just don't see it as that much of a major optimization or really a major issue to do it that way. The code was working fine with strcpy after the fixes that OddObserver pointed out, so I don't see where you get off on telling me to optimize after I have a correct version.
|
# ? May 17, 2010 18:43 |
|
SintaxError posted:All 'retardedness' aside, I guess I just don't see it as that much of a major optimization or really a major issue to do it that way. The code was working fine with strcpy after the fixes that OddObserver pointed out, so I don't see where you get off on telling me to optimize after I have a correct version. Because that is the correct way to do good optimization, but hey, we're not worried about correctness
|
# ? May 17, 2010 19:03 |
|
Think about it this way: if you knew how to optimize properly, you wouldn't have had to waste other people's time telling you how to write your code because you'd already have a working version. More to the point: if you have to ask someone else how to properly handle manual memory management, you shouldn't be manually managing memory. (Try saying that five times fast.)
|
# ? May 17, 2010 19:09 |
|
OK, I understand that. However, the code was correct before I 'optimized' it. Again, I don't really even see storing words as pointers into a tokenized buffer as some sort of major complicated optimization - it's not like I'm manually unrolling loops. I only see it as an efficient use of time/memory given the requirements of the program. At any rate, the program runs well now. Edit: furthermore, had I done it with pointers into the buffer from the start, I would have never even run into the original problems which were caused by problems creating/deleting the tableEntry's word. Colonel Taint fucked around with this message at 19:23 on May 17, 2010 |
# ? May 17, 2010 19:17 |
|
Just to throw my two cents in: my rule is that the word "optimization" doesn't enter my vocabulary until I've thrown my program at a profiler.
|
# ? May 17, 2010 19:19 |
|
The main problem with doing things a certain way because 'it's a small app' when learning is that anything real you make won't be small, so it'll be harder to establish whether the shortcuts you take are actually safe. And in most real things, you likely won't know what parts are performance-critical until you profile, anyway, or whether the performance even matters (if you're taking 2ms vs. 1.8ms, it's probably not worth the effort). C-style strings are actually a problematic approach when you're trying to be fast, too, since they do not express ownership, so in general you may end up making far more deep copies than, say, with a reference-counted COW string class, or more allocations than with a small-value optimization string class. I think an important thing to keep in mind with C++ is that abstractions can be /good/ for performance work, since they put a lot mechanics of how stuff works in one place, letting you improve it w/o having to rework everything --- and C++ gives you a lot of tools like inlining and templates to eliminate the abstraction overhead itself.
|
# ? May 17, 2010 19:25 |
|
Let me just say I agree with all of that. Just to defend myself, I have to point out that I'm not just learning C++, and I was really just doing this as an exercise to start re-familiarizing myself with the C/C++ environment after spending the last year or so deep in higher level language code. I was well aware of the program requirements beforehand, and I think I made the right choices for exactly what needed to be done.
|
# ? May 17, 2010 19:43 |
|
|
# ? Jun 8, 2024 16:58 |
|
SintaxError posted:I think I made the right choices for exactly what needed to be done.
|
# ? May 17, 2010 20:22 |