|
They wanted to replace ().
|
# ? Dec 9, 2012 00:01 |
|
|
# ? Jun 8, 2024 09:22 |
|
I was wondering if anybody here has played with OpenCL. I'm finding it to be extremely finicky to get started. I installed the AMD APP SDK, and started trying to use some samples online. Generally the calls there will just plain fail. I found the samples in the AMD SDK, and managed to one of those to compile and run. It ties in other projects in the example Visual Studio solution file, so I had a hell of a time using it in a different solution. The syntax in the AMD APP SDK looks very different. Their examples are using a C++ model with namespaces and everything. It looks to be doing similar things to the C calls in all the other sample code I see around. I wondered if that's AMD's thing, or if that's a newer spec than a lot of stuff online. I had started to read some stuff through my Safari subscription, and all those examples don't directly relate to the stuff in the AMD SDK.
|
# ? Dec 9, 2012 09:09 |
|
Suspicious Dish posted:Did they really not want to type = or? If you use an equal sign, then it will create a temporary from the initialization list and then invoke a copy-constructor. EDIT: This is wrong, in case anybody reads this and doesn't read the next few posts. FamDav fucked around with this message at 10:23 on Dec 13, 2012 |
# ? Dec 9, 2012 09:20 |
|
FamDav posted:If you use an equal sign, then it will create a temporary from the initialization list and then invoke a copy-constructor. That's not true. When you use "=" in initialization it's just syntactic sugar (this is standard, not even an optimization). The object will not be copied.
|
# ? Dec 9, 2012 09:48 |
|
Right, and even if it weren't, "initialize this local from a temporary of the same type" is basically a universal optimization — it's trivial to implement and pervasive in applicability. Now, assigning a local from a temporary still builds the temporary, and the compiler can't legally do anything about it (other than with as-if reasoning). That's an important intuition for any C++ programmer, and there's no surer way to embarrass yourself as a C++ interviewee than to not understand the difference (not that it should be fatal if don't claim experience with C++ — just that if you do, getting this stuff right is pretty critical).
|
# ? Dec 9, 2012 10:55 |
|
rjmccall posted:Right, and even if it weren't, "initialize this local from a temporary of the same type" is basically a universal optimization — it's trivial to implement and pervasive in applicability. When interviewing people for an engineering position, I always ask them to rate themselves on a scale of 1-10 with how well they know C++. Anytime someone self-rates themselves as a 9 or 10 I ask RVO questions. I hate people who self rate at 9 or 10 and are really at like a 6 or 7.
|
# ? Dec 9, 2012 15:36 |
|
I don't really like the "rate yourself from 1-10 questions" just from experience, I worked at a few places where if you rated yourself 6-7 you'd just be shitlisted, but if you rated yourself 9-10 you'd be asked obnoxious edge-case questions that make you look retarded (despite being the kind of questions where if it was an actual practical issue you'd refer to the spec/docs anyway). Even for languages I'm proficient and efficient with (definitely not C++) I won't rate myself above an 8 ever just because I'm wary of the interviewer having one rear end in a top hat of a question up their sleeve.
|
# ? Dec 9, 2012 15:58 |
|
Hughlander posted:When interviewing people for an engineering position, I always ask them to rate themselves on a scale of 1-10 with how well they know C++. Anytime someone self-rates themselves as a 9 or 10 I ask RVO questions. I hate people who self rate at 9 or 10 and are really at like a 6 or 7.
|
# ? Dec 9, 2012 16:11 |
|
The Gripper posted:I don't really like the "rate yourself from 1-10 questions" just from experience, I worked at a few places where if you rated yourself 6-7 you'd just be shitlisted, but if you rated yourself 9-10 you'd be asked obnoxious edge-case questions that make you look retarded (despite being the kind of questions where if it was an actual practical issue you'd refer to the spec/docs anyway). I hate all interview questions for similar reasons. I got asked to write a bit of code to convert an unsigned integer to a decimal-representation string without using any of the printf/itoa sort of functions, so I wrote one that walked down from the maximum possible number of digits before writing out the present digits. The guy said I should have used 'log' rather than walking down the up to 10 digits it would take to get to the start of the number. gently caress off guy, first you're telling me I'm not supposed to use prepackaged functions to do the task and then you're telling me to use one that's barely appropriate to make the tiniest loving difference in a way that only makes the code more awkward, less readable, and slower? (I just tried it, a million repetitions on a four digit number took 360ms with my version, 960ms with a version using log. sprintf also takes 360ms.) But of course you can't tell an interviewer that their "correction" is rubbish, so what are you supposed to do here? vvvv I went with "I'm pretty sure that way would be slower", and I didn't get the job, so yay. Though I suppose it's more likely that I didn't get it because I didn't really want it that much anyway, don't hide my feelings well, and probably insulted their whole business model or something too, I tend to do that. roomforthetuna fucked around with this message at 16:48 on Dec 9, 2012 |
# ? Dec 9, 2012 16:34 |
|
Tell them their correction is rubbish. Because it is.
|
# ? Dec 9, 2012 16:40 |
|
In my mind though the whole purpose of interviewing is not for the knowledge you know but the way that you think. It's like what Gripper/tuna said, in an actual real life example you'll use google and read the specs, write unit tests and have them run etc... However, I like to have a fairly simple problem for them to solve then slowly mutate it into more and more complex issues to see how the candidate deal with that. Because that's poo poo that we put up with all the time. Requirements change, code that was straight forward needs more and more complex validation as edge cases pop-up. At this point though I'm sorry for the derail.
|
# ? Dec 9, 2012 16:53 |
|
Pretty much. Most of the awful questions come from people that didn't think it up themselves anyway/don't have a solid programming background, so they treat answers to what amounts to a "creative problem" in a black and white way without much consideration. (also apologies for the derail, and I wasn't suggesting RVO was one of these horrible questions since it's something that actually matters.)
|
# ? Dec 9, 2012 17:38 |
|
The Gripper posted:Pretty much. Most of the awful questions come from people that didn't think it up themselves anyway/don't have a solid programming background, so they treat answers to what amounts to a "creative problem" in a black and white way without much consideration. That literally is my question, "What is RVO and why should you know about it?"
|
# ? Dec 9, 2012 18:08 |
|
That Turkey Story posted:That's not true. When you use "=" in initialization it's just syntactic sugar (this is standard, not even an optimization). The object will not be copied. Hughlander posted:That literally is my question, "What is RVO and why should you know about it?" Is it bad that I (obviously) didn't know that the equals sign was meaningless in copy-initialization but knew about RVO? I swear C++. EDIT: Okay, I think I see where I was confused. I had assumed that "F f0 = {12}" would be equivalent to "F f0 = F{12}" when it's really equivalent to "F f0(12)", which seems different than copy initialization? That is, "F f0 = 12" is equivalent to "F f0(F(12))" is equivalent to "F f0 = F(12)" but not "F f0(12)". This is assuming no copy elision. FamDav fucked around with this message at 22:02 on Dec 9, 2012 |
# ? Dec 9, 2012 20:43 |
|
mobby_6kl posted:Anyway, this is pretty much my first C++ project and...
|
# ? Dec 9, 2012 22:22 |
|
So, my entire class' projects have been optionally c++/java, and, seeing as I've been trained in C++, that's what I've been using. Well, my teacher is giving the final projects in Java-specific terms, so I was wondering if anyone knows if this assignmentquote:Your job is to write a method: is doable in C++ terms and how I should approach it?
|
# ? Dec 9, 2012 23:25 |
|
an skeleton posted:So, my entire class' projects have been optionally c++/java, and, seeing as I've been trained in C++, that's what I've been using. Well, my teacher is giving the final projects in Java-specific terms, so I was wondering if anyone knows if this assignment Yes. Think of how you would ideally want to solve the problem, then recognize that std::map let's you do that easily.
|
# ? Dec 9, 2012 23:42 |
|
FamDav posted:Yes. Think of how you would ideally want to solve the problem, then recognize that std::map let's you do that easily. ok, so there is a library (i think that's what it's called?) in c++ for that. cool, thanks.
|
# ? Dec 10, 2012 00:13 |
|
an skeleton posted:ok, so there is a library (i think that's what it's called?) in c++ for that. cool, thanks. std::map and and an intersect algorithm in <algorithm> will let you do this in a couple of lines of code. However, your teacher is probably looking for you to at least write the algorithm yourself, if not the map too.
|
# ? Dec 10, 2012 02:05 |
xgalaxy posted:std::map and and an intersect algorithm in <algorithm> will let you do this in a couple of lines of code. However, your teacher is probably looking for you to at least write the algorithm yourself, if not the map too. When the task set directly mentions HashMap<String,String> I assume the teacher intends them to use the HashMap class provided by the Java standard library, meaning that using a map class from the STL should be fine too. (Worth a note is that Java's HashMap is actually equivalent to STL's std::unordered_map, although it doesn't make a real difference here. Just use std::map since you don't create a dependency on C++11 or TR1 that way.)
|
|
# ? Dec 10, 2012 02:19 |
|
Ok, I have to do a cache simulation program in C++. We have never done C++ before and I am really confused on how to start. We have a simulation.cc file which holds the main. Then we have cache, set, and block which each have a .cc and .o file. I feel like I understand the concept of cache, but I have sat here staring at my screen for hours and literally have no idea how to start and my TA didn't know what to do either. Like how do I make a block given a block size of 2 bytes or 4 bytes? Suran37 fucked around with this message at 02:44 on Dec 10, 2012 |
# ? Dec 10, 2012 02:31 |
|
Yea, using the hashmap class or equivalent is ok, i just have to write the algorithm.
|
# ? Dec 10, 2012 03:43 |
|
awesmoe posted:What compiler are you using? I think you need vs2012 with the new CTP for that to work (or at least, for that syntax to work everywhere). Turns out I'm wrong and this C++ code:
code:
awesmoe fucked around with this message at 06:00 on Dec 10, 2012 |
# ? Dec 10, 2012 04:38 |
|
The compiler supports it, but the standard library hasn't been updated yet.
|
# ? Dec 10, 2012 05:19 |
|
If I create a 2d dynamic array withcode:
code:
|
# ? Dec 11, 2012 18:51 |
No, you need to use delete[] picture[x]; because the value was allocated as an array. However you shouldn't be allocating your picture that way at all. Allocate it as one large hunk of memory (with w*h elements) and use y*w+x type indexing into it.
|
|
# ? Dec 11, 2012 19:05 |
|
The non-contiguous memory issue did come up, but the course leader didn't say anything about that method of allocating it, or that anyone was doing it wrong, even though it affects another part of the assessment where we have to use pointer arithmetic. I can't be bothered to start rewriting everything this close to Christmas, so I'm just going to hope we won't get marks docked for it, but thanks for the info, it should make this a lot easier in future.
|
# ? Dec 11, 2012 19:32 |
You can still allocate one large block and then make an additional array with pointers into that block for each row (or column, if you want to index reverse of what's commonly used.)C++ code:
|
|
# ? Dec 11, 2012 19:42 |
|
To clarify nielsm's first reply, using your original allocation scheme, the correct way to delete it is:C++ code:
|
# ? Dec 11, 2012 22:43 |
|
I've been playing with implementing some thread patterns I've used in the past with std::thread ( and VS2012 if that matters ). One pattern I use is a worker thread which is doing something periodically and also needs to be told when to stop. Is the following code correct usage of C++11? C++ code:
|
# ? Dec 11, 2012 23:58 |
|
fankey posted:I've been playing with implementing some thread patterns I've used in the past with std::thread ( and VS2012 if that matters ). One pattern I use is a worker thread which is doing something periodically and also needs to be told when to stop. Is the following code correct usage of C++11? Unless what you mean by "working" is literally just waiting on a condition variable until told to stop, what you want is something along the lines of this: C++ code:
|
# ? Dec 12, 2012 01:37 |
|
b0lt posted:Unless what you mean by "working" is literally just waiting on a condition variable until told to stop, what you want is something along the lines of this: Whereas, if the 'period' was long, your way with the sleep would be more of a problem because the 'die' signal wouldn't be responded to until after the timeout. roomforthetuna fucked around with this message at 03:45 on Dec 12, 2012 |
# ? Dec 12, 2012 03:24 |
|
roomforthetuna posted:Well, he said "periodically" doing something, and his code was waiting for one second (or a 'die') then either doing stuff or exiting. So his way would work okay for what he said, I think. (Though some confusion about 'lock' being made twice, I don't think that's quite right, but there should be a mutex or signal or something that does what he wants.) The sleep is a stand-in for <do work>, what he had would not work if it does anything other than wait on the condition variable, because condition variables are not semaphores and notifying a condition variable that isn't being waited upon will not signal a future wait() call. The following code (which would be equivalent to what he had, if die() is called while the worker thread is working and not waiting on the condition variable) deadlocks: C++ code:
|
# ? Dec 12, 2012 03:56 |
|
b0lt posted:notifying a condition variable that isn't being waited upon will not signal a future wait() call. code:
On a similar note, is there a way using std::thread stuff to wait on multiple things at once? Say my worker had a queue of jobs and when something was added to the queue I want to execute it immediately. I think I could just wait on my add_job condition_variable for x seconds and exit ( similar to what you originally posted ) but ideally I'd be able to wait on both the add_job and some sort of thread_death object so I can kill the thread as soon as possible. This sort of thing is important because my code runs in soft real time systems where I might need to shut down threads and relaunch within 30ms.
|
# ? Dec 12, 2012 05:48 |
|
b0lt posted:The sleep is a stand-in for <do work>, what he had would not work if it does anything other than wait on the condition variable, because condition variables are not semaphores and notifying a condition variable that isn't being waited upon will not signal a future wait() call. The following code (which would be equivalent to what he had, if die() is called while the worker thread is working and not waiting on the condition variable) deadlocks: 1. a thread is spawned, sharing mutex and cv. 2. the thread acquires a lock on the mutex. 3. the thread releases the lock and suspends until cv is notified. (meanwhile the original thread sleeps) 4. original thread notifies. spawned thread reacquires the lock. 5. original thread sleeps. spawned thread notifies. 6. original thread acquires a lock (do we block here because the lock is on the same mutex and the other thread still has a lock? Or is it okay because the other thread ended already?) 7. original thread waits for a notification that never comes because it arrived too early. If I'm reading that right then fankey's original code shares the same problem, but wouldn't actually lock up when it occurs, it would just potentially fail to exit and keep running its "increment and output a variable" work if the timing of the 'die' call was unlucky, because the unmet "wait_for" would continue to time out. And in that case it sounds like the actual question is "how do you implement a semaphore in C++11?" To which the answer appears to be "almost how fankey did, only with the addition of a 'count' that gets incremented after the lock but before the notify when you call 'die', that is checked after the lock in the thread but before the 'wait', and that is decremented either when the wait is aborted or the check was positive. I think that would achieve the "work and sleep" model fankey was asking for without the potential delay to death that b0lt's solution came with.
|
# ? Dec 12, 2012 08:52 |
|
You guys happen to be talking about some stuff that I was always hoping to find clarified anyways. I've had some situations in the past where I was using a condition variable, and a race condition where the waiter waits after the notifier notifies. So the waiter gets stuck. I had to set up more advanced criteria to make sure the waiter checked some variable indicating the notification already happened. I thought it was clumsy, and also that in some situations this didn't happen. For example, I could swear in .NET that monitors don't have this problem, but now I'm not sure. Are you guys saying a semaphore is better for this kind of stuff? If I had to, say, just do a single notification--rather than looping on the condition variable or whatever--what is the most proper way to maintain that variable? I'm fearing that I have been screwing this up. In Boost, I would provide a predicate function to test that boolean, and I would make the boolean volatile. I can't remember if I'd lock it first, but I know I should. I don't know if I'd need to make it volatile if it was locked.
|
# ? Dec 12, 2012 20:14 |
|
Rocko Bonaparte posted:You guys happen to be talking about some stuff that I was always hoping to find clarified anyways. I've had some situations in the past where I was using a condition variable, and a race condition where the waiter waits after the notifier notifies. So the waiter gets stuck. I had to set up more advanced criteria to make sure the waiter checked some variable indicating the notification already happened. I thought it was clumsy, and also that in some situations this didn't happen. For example, I could swear in .NET that monitors don't have this problem, but now I'm not sure. It'd be really weird if .NET monitors worked that way, considering it has semaphores too. It's pretty easy to just write a semaphore using condition_variables and mutexes: C++ code:
b0lt fucked around with this message at 21:28 on Dec 12, 2012 |
# ? Dec 12, 2012 21:25 |
|
I am working on a cache simulator. After my program runs I am getting a *** glibc detected *** ./p3.out: double-free or corruption (out). So, it runs the program fine then throws that. The funny thing is that I don't have any mallocs, frees, etc however, some googling has led me to believe it might because by vectors which I am using. Does anybody have any ideas? I can post code if it helps, but I have no idea where the error is throwing. EDIT: Upon further review I forgot to move a for loop down after rewriting a section of code. Suran37 fucked around with this message at 23:53 on Dec 12, 2012 |
# ? Dec 12, 2012 22:49 |
|
Yes, please post some code.
|
# ? Dec 12, 2012 23:25 |
|
|
# ? Jun 8, 2024 09:22 |
|
GrumpyDoctor posted:Yes, please post some code. I figured it out. I was originally passing the number of lines per set in through the command prompt, but our spec doesn't so I had to re-write that part and forgot to move the for loop that created the vector of sets down after it calculated the lines per set. Somewhere down the line that was causing a problem I guess.
|
# ? Dec 12, 2012 23:55 |