C++ :: How Are Members Accessed In AMP Restricted Methods
May 17, 2013
Suppose I have a class "A", which has a method "void AMP_call()" that calls paralel_for_each in which another method, "float amp_function(float) restrict(amp)". When I call that method, can it then use members of "A"?
class A {
void AMP_call();
float amp_function(float) restrict(amp); // do something on a device
float allowed_variable;
std::vector<bool> not_allowed;
[Code] ....
Another way to frame my question, perhaps to make it easier to understand what I am after, would be that I want to know what happens if an amp-restricted method is called where the body of the class itself (which is not amp-compatible and afaik doesn't have to be since it's not passed to the device) may contain members that are not amp-compatible.
All of the msdn blogs I could find deal with which functions and methods can be called from within a parallel_for_each loop, but not with which variables are available to the lambda function itself.
"A nested class has free access to all the static members of the enclosing class. All the instance members can be accessed through an object of the enclosing class type, or a pointer or reference to an object."
How can the members be accessed through an object of the enclosing class type? I understand the pointer and reference part because for them you dont need the full definition, but for creating a object you do?
Also it has free access to all static members because the nested class is part of the enclosed class and with static it exists in everything inside the enclosing class? Right or am I missing something?
How to tell whether a variable has been accessed in memory, no matter what it's been used for... Whether it's actually been set to something else, or whether it's been get for an operation or function call that doesn't actually do anything to affect the variable itself. Either way the variable has been "accessed" for something.
I'm not entirely certain that it's possible to detect a program getting the variable but I know that programs exist where they can trace what has accessed a certain part of memory... CheatEngine is one example, although I'm not entirely sure whether this can only detect changes in the variable and then trace what did it
I'm redesigning some code and I'm wondering what the best ways to store and access certain data is. The characteristics are as followed:
1) Based on data from a file, a distance matrix (N x N) is calculated. 2) Once the matrix is complete, the data will never change (unless a new file is read, but I can work around that by iteratively calling the problem with a new datafile on as command line parameter). 3) The data from the matrix is accessed billions of times from pretty much every other line of code.
In my old version, I had a class "Data" which a sub-class "Data::Distance" and I would put a reference in every other class that needed it. Now, my class hierarchy will be much flatter (basically all logic will be in one class; other classes will be POD structs).
Given the characteristics of the Distance table, is there a way to store them in a very efficiently-accessible way? Does it matter if it's stored in the main class where all the action happens in contrast to being a different class? Does making it static improve the performance? Casting it to const? Anything?
Again, the data is accessed billions of times so even minor differences can save a lot of time.
The idea of the code is to make a console to parse some commands. And have some commands with arguments and others no. Without the static the program return other error that is...
I currently have globally declared arrays, which are accessed by multiple functions. I want to turn the program so that the arrays are no longer globally declared, but are passed to functions by reference.
I have one problem with passing the arrays: I found that, through debugging, I HAVE TO resize the array when I pass it by reference. For instance, I was using int a[10] when it was globally declared, when it is passed by reference with size 10, it does not work, instead it should be higher than 10 (certain number). Why is this happening? I do not get it...
I have questions about multiple inheritance and virtual methods. I have a class called solid. All objects of this class have hitboxes and can collide with others. I have the following methods:
void testCollision(something begin, something end); /* This method takes a container's begin and end iterators to test if the object collides with any other object of the list of all the solids currently in the game area. Each time there is a collision, it calls collide(other) and other.collide(*this) */
virtual bool collide(solid& other); /* This method always returns false and does nothing */
This class will be inherited by another class which will have overloads for a few specific collisions. For example:
class player : public solid{ public: bool collide(projectile& other); bool collide(enemy& other); bool collide(wall& other); };
My question is quite simple actually. If I have a loop which calls testCollision() with all elements in the list of all solids (a list of pointers to solids to be exact) and there is a collision between the player and a projectile, will testCollision call player::colide(projectile& other) or will it call solid::collide(solid& other). And in any case, did I understand how to use the virtual keyword? If I'm right, it should call the player::colide method if it's there for the specific type, else it will call the solid::colide which only returns 0, ignoring collision.
I have h-file with definition of 3 classes. And cpp-file with realization methods of this classes. And when I compile the project errors - LNK2019 is apperead... How make that methods become visible?
I'm writing a sorted vector implementation and trying to do it as simply as possible.
Right now, I'm declaring the sorted vector with a protected subclass of vector, then using the "using" keyword to explicitly inherit all methods that aren't related to adding new elements to the vector (so I can control the order).
Eg:
Code: template<typename T, class Cmp = std::less<T>> class sorted_vector : protected std::vector<T>{ public: typedef typename std::vector<T>::iterator; using std::vector<T>::operator=; using std::vector<T>::assign; using std::vector<T>::get_allocator; using std::vector<T>::at; using std::vector<T>::operator[]; //... };
Obviously, this is annoyingly redundant. So what I'd like to do is something using the new "delete" keyword from C++11. Is there any quick, expressive way of deleting specific methods?
Also, it's pretty annoying to have to typedef base_class::type type to inherit a type from a base class. Is there a shorter way to do that?
I'd like to be able to add additional class-methods through lua for any classes that I've bound in c++, but I'm unsure how to do it.
The problem is that luabind uses a function as the __index-metamethod for any bound classes instead of a table, so I don't see a way to access the class-methods at all.
What I essentially want to do is to add a lua-function to the list of methods for this class, and be able to overwrite existing ones:
local t = tableOfClassMethods local r = t.TestFunc -- Reference to the c++-function we've bound t.SomeFunction = function(o) end -- New function for all objects of this class t.TestFunc = function(o) end -- Should overwrite the c++-function of the same name
i have been trying to call out the tea algorithm from wikipedia. However i keep getting a segmentation fault. Am i calling it out the wrong way? Below are the snippets
methods taken from wikipedia
void encrypt (uint32_t* v, uint32_t* k) { uint32_t v0=v[0], v1=v[1], sum=0, i; /* set up */ uint32_t delta=0x9e3779b9; /* a key schedule constant */ uint32_t k0=k[0], k1=k[1], k2=k[2], k3=k[3]; /* cache key */ for (i=0; i < 32; i++) { /* basic cycle start */ sum += delta;
[code]....
i tried to encrypt a test text and casting it to the uinstd32_t type. However it always gives me a segmentation fault.
I know that memory addresses in the stack can contain either values or references to other memory addresses, but do these memory addresses also contain methods or are the methods themselves located in the heap?
The confusion comes from the fact that in C# a delegate variable can be assigned either a method's identifier, an inline function, a lambda expression, or a new instance of the delegate type with the method's identifier passed as an argument to the constructor. My guess is that assigning the method's identifier directly to the delegate variable is just a simplified way of calling the delegate type's constructor with the method's identifier as an argument to the parameter, something that the compiler handles for you.
But even in this last case, the delegate variable is said to point toward the method itself. In that case, does it mean that methods are stored in the heap, just as reference type values are?
I need to override a few methods in FILE class so i defined few methods as
EnCrpt * fp; fp * fopen(const char * filename, const char * mode); int fwrite(const void * p,int length,int readLenth,FILE * fpp = NULL); int fread(void * p,int length,int readLenth,FILE * fpp = NULL); int fseek(FILE * fpp = NULL,long offset, int whence); long ftell(FILE * fpp = NULL); int feof(FILE * fpp = NULL); int fflush(FILE * fpp = NULL); int fclose(FILE * fpp = NULL);
I will call fread method in my encrypted file class .. similar to other methods.. is this correct ? can NULL file pointer create issue ?
Because i have so many place where FILE class called i don't want to change everywhere to call encrypted file class so i am override these methods to encrypted file class instead of standrd FILE class
I need to write a windows form application that allows the user to enter a credit card number and credit card type and then determines whether it is a valid number using the following rules:
1.) the first number is:
a. 4 for visa b. 5 for master card c. 37 for american express d. 6 for discover
2.) passes the mod 10/ luhn check, which is calculated as:
a. from right to left, multiply every other digit by 2. when doubling a digit results in a two digit number, add the numbers to get
a single digit. ( like 6 * 2 = 12 therefore 1 + 2 = 3).
b. add all the single digits from 2a
c. add all the odd places from right to left in the card number
d. sum the results fro steps 2b and 2c
e. if the resulting number in 2c is divisible by 10, the card number is valid otherwise it is invalid.
The chapter is introducing methods so that is the main thing i will be using for each step.
I have a template class which defines a few heavy methods. For now, they are defined in the same .h file as the class definition, but i`d like to have them in a separate .cpp file.
A situation i find you describe in the FAQs arises: [URL] ....
Problem: the export keyword has been deprecated in c++0x, if i recall correctly, and has never been implemented in any of the compilers i am using (msvc, gcc).
#Including the the .cpp file after the class definition (as described in the second post of the FAQ) works.
another question: i have methods that dont use any template code. Can i somehow declare them as such? (more of an esthecial question, which would make it easier to distinguish between template and non.template code).
I've been experimenting with char arrays and getting user input through different methods.
int main() { char userInput[21]; /*I understand that over here, a maximum of 20 letters can be input, and only letters before a space will be stored in userInput*/ std::cin >> userInput; std::cout << userInput << std::endl;
[Code] ....
As I was testing, whenever I would input a single word for userInput (for example "hi"), the program would work as expected: it would output "hi" and I'd be able to input a sentence of sorts for userInput2 (for example "hello world") and have it outputted.
But if I were to input more than one word for user Input (for example "hi how are you"), the program would output "hi" as expected, but it wouldn't let me input anything for userInput2 and would just output the rest of the first input; in this case, "how are you" would be outputted and the program would end. I am not aware of the logic error at play.