Search Results

Search found 2562 results on 103 pages for 'vector'.

Page 55/103 | < Previous Page | 51 52 53 54 55 56 57 58 59 60 61 62  | Next Page >

  • Send a variable on the heap to another thread

    - by user1201889
    I have a strange problem in C++. An address of a Boolean gets "destroyed" but it doesn't get touched. I know that there are beater way's to accomplish what I try to do, but I want to know what I do wrong. I have a main class; this main class contains a vector of another class. There is a strange problem when a new instance gets created of this object. This is how my code works: There will start a thread when the constructor gets called of the “2nd”object. This thread gets as Parameter a struct. This is the struct: struct KeyPressData { vector<bool> *AutoPressStatus; vector<int> *AutoPressTime; bool * Destroy; bool * Ready; }; The struct gets filled in the constructor: MultiBoxClient::MultiBoxClient() { //init data DestroyThread = new bool; ReadyThread = new bool; AutoThreadData = new KeyPressData; //Reseting data *DestroyThread = false; *ReadyThread = false; //KeyPressData configurating AutoThreadData->AutoPressStatus = &AutoPressStatus; AutoThreadData->AutoPressTime = &AutoPressTime; AutoThreadData->Destroy = DestroyThread; AutoThreadData->Ready = ReadyThread; //Start the keypress thread CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)AutoKeyThread,AutoThreadData,NULL,NULL); } As long as the constructor is running will the program run fine. But when the constructor closes the address of the “AutoThreadData-Destroy” will get corrupted. The program will crash when I call the value of the pointer. void WINAPI AutoKeyThread(void * ThreadData) { KeyPressData * AutoThreadData = (KeyPressData*)ThreadData; while(true) { if(*AutoThreadData->Destroy == true) //CRASH { *AutoThreadData->Ready = true; return; } Sleep(100); } } What did I test: I logged the address of the AutoThreadData and the AutoThreadData-Destroy when the constrcutor is running and clossed; the AutoThreadData address is equal to AutoThreadData when the constructor is closed. So there is no problem here. The address of AutoThreadData-Destroy gets destroyed when the constructor is closed. But how can this happen? The Boolean is on the heap and the KeyPressData struct (AutoThreadData) is on the heap. Destroy before: 00A85328 Destroy after: FEEEFEEE Can someone maby explain why this crash? I know that I can send a pointer to my class to the thread. But I want to know what goes wrong here. That way I can learn from my mistakes. Could someone help me with this problem? Thanks!

    Read the article

  • is there a way to use cin.getline() without having to define a char array size before hand?

    - by zebraman
    Basically my task is having to sort a bunch of strings of variable length ignoring case. I understand there is a function strcasecmp() that compares cstrings, but doesn't work on strings. Right now I'm using getline() for strings so I can just read in the strings one line at a time. I add these to a vector of strings, then convert to cstrings for each call of strcasecmp(). Instead of having to convert each string to a cstring before comparing with strcasecmp(), I was wondering if there was a way I could use cin.getline() for cstrings without having a predefined char array size. Or, would the best solution be to just read in string, convert to cstring, store in vector, then sort?

    Read the article

  • How is the syntax for stl iterators implemented?

    - by Liberalkid
    I've been working on writing a library in my spare time to familiarize myself more with c++ and singular value decomposition. I've been working on writing an Iterator class and I'm entirely capable of writing the functionality and I have already for my own currently MatrixIterator class. I'm guessing that it involves namespaces because: vector<int>::iterator Would appear to be an iterator from the namespace vector, but namespaces are another topic which I'm not familiar with. Mainly I'm asking what would it involve to implement an iterator such that it could be referenced in a similar way to the stl iterators. I'm also aware that I could use boost.iterators or something similar to save myself a lot of work, but I'm more interested in learning all of the details that go into something like this.

    Read the article

  • Connection between Properties of Entities in Data Oriented Design

    - by sharethis
    I want to start with an example illustrating my question. The following way it is done in the most games. class car { vec3 position; vec3 rotation; mesh model; imge texture; void move(); // modify position and rotation void draw(); // use model, texture, ... }; vector<car> cars; for(auto i = cars.begin(); i != cars.end(); ++i) { i->move(); i->draw(); } Data oriented design means to process the same calculation on the hole batch of data at once. This way it takes more advantage out of the processor cache. struct movedata { vec3 position; vec3 rotation; }; struct drawdata { mesh model; imge texture; }; vector<movedata> movedatas; vector<drawdata> drawdatas; for(auto i = movedatas.begin(); i != movedatas.end(); ++i) { // modify position and rotation } for(auto i = drawdatas.begin(); i != drawdatas.end(); ++i) { // use model, texture, ... } But there comes a point where you need to find other properties according to an entity. For example if the car crashes, I do not need the drawdata and the movedata any more. So I need to delete the entries of this entity in all vectors. The entries are not linked by code. So my question is the following. How are properties of the same entity conceptually linked in a data oriented design?

    Read the article

  • How to input test data using the DecisionTree module in python?

    - by lifera1n
    On the Python DescisionTree module homepage (DecisionTree-1.6.1), they give a piece of example code. Here it is: dt = DecisionTree( training_datafile = "training.dat", debug1 = 1 ) dt.get_training_data() dt.show_training_data() root_node = dt.construct_decision_tree_classifier() root_node.display_decision_tree(" ") test_sample = ['exercising=>never', 'smoking=>heavy', 'fatIntake=>heavy', 'videoAddiction=>heavy'] classification = dt.classify(root_node, test_sample) print "Classification: ", classification My question is: How can I specify sample data (test_sample here) from variables? On the project homepage, it says: "You classify new data by first constructing a new data vector:" I have searched around but have been unable to find out what a data vector is or the answer to my question. Any help would be appreciated!

    Read the article

  • Plotting a grouped 2 dimensional vevtor in MATLAB

    - by Hossein
    Hi, I am trying to make a plot of a 2-Dimensional vector(2D Plot).But I don't want all the datapoints to have the same color on the plot.Each datapoint corresponds to a group.I want to have different colors for each group of datapoints. class=[1 3 2 5 2 5 1 3 3 4 2 2 2] says each datapoint belongs to which group X=[x1,y1;x2,y2;x3,y3;.....] the number of thes datapoints are the same as the number of elements in th class vector. Now I want to plot these based on colors. Can someone help me? Thanks

    Read the article

  • How to load modules in Java

    - by gerardorn
    I'm building a server that loads modules. Each module is a .jar file. Inside the jar there's all the classes that the module needs. The server needs to read the jar, find the main class (it doesnt have the main method on it is just the class that makes the module work but not as a different program), build an object of that class and store it in a vector of modules so that it can acces to a specific module depending on the job to be done. How can I do that? As far as the server, it is listening and receiving request, but there's no modules to delegate the job to, since my vector of modules is empty.

    Read the article

  • C++ split string

    - by Mike
    I am trying to split a string using spaces as a delimiter. I would like to store each token in an array or vector. I have tried. string tempInput; cin >> tempInput; string input[5]; stringstream ss(tempInput); // Insert the string into a stream int i=0; while (ss >> tempInput){ input[i] = tempInput; i++; } The problem is that if i input "this is a test", the array only seems to store input[0] = "this". It does not contain values for input[2] through input[4]. I have also tried using a vector but with the same result.

    Read the article

  • How to use an adjacency matrix to determine which rows to 'pass' to a function in r?

    - by dubhousing
    New to R, and I have a long-ish question: I have a shapefile/map, and I'm aiming to calculate a certain index for every polygon in that map, based on attributes of that polygon and each polygon that neighbors it. I have an adjacency matrix -- which I think is the same as a "1st-order queen contiguity weights matrix", although I'm not sure -- that describes which polygons border which other polygons, e.g., POLYID A B C D E A 0 0 1 0 1 B 0 0 1 0 0 C 1 1 0 1 0 D 0 0 1 0 1 E 1 0 0 1 0 The above indicates, for instance, that polygons 'C' and 'E' adjoin polygon 'A'; polygon 'B' adjoins only polygon 'C', etc. The attribute table I have has one polygon per row: POLYID TOT L10K 10_15K 15_20K ... A 500 24 30 77 ... Where TOT, L10K, etc. are the variables I use to calculate an index. There are 525 polygons/rows in my data, so I'd like to use the adjacency matrix to determine which rows' attributes to incorporate into the calculation of the index of interest. For now, I can calculate the index when I subset the rows that correspond to one 'bundle' of neighboring polygons, and then use a loop (if it's of interest, I'm calculating the Centile Gap Index, a measure of local income segregation). E.g., subsetting the 'neighborhood' of the Detroit City Schools: Detroit <- UNSD00[c(142,150,164,221,226,236,295,327,157,177,178,364,233,373,418,424,449,451,487),] Then record the marginal column proportions and a running total: catprops <- vector() for(i in 4:19) { catprops[(i-3)]<-sum(Detroit[,i])/sum(Detroit[,3]) } catprops <- as.data.frame(catprops) catprops[,2]<-cumsum(catprops[,1]) Columns 4:19 are the necessary ones in the attribute table. Then I use the following code to calculate the index -- note that the loop has "i in 1:19" because the Detroit subset has 19 polygons. cgidistsum <- 0 for(i in 1:19) { pranks <- vector() for(j in 4:19) { if (Detroit[i,j]==0) pranks <- append(pranks,0) else if (j == 4) pranks <- append(pranks,seq(0,catprops[1,2],by=catprops[1,2]/Detroit[i,j])) else pranks <- append(pranks,seq(catprops[j-4,2],catprops[j-3,2],by=catprops[j-3,1]/Detroit[i,j])) } distpranks <- vector() distpranks<-abs(pranks-median(pranks)) cgidistsum <- cgidistsum + sum(distpranks) } cgi <- (.25-(cgidistsum/sum(Detroit[,3])))/.25 My apologies if I've provided more information than is necessary. I would really like to exploit the adjacency matrix in order to calculate the CGI for each 'bundle' of these rows. If you happen to know how I could started with this, that would be great. and my apologies for any novice mistakes, I'm new to R!

    Read the article

  • Nested for_each with lambda not possible?

    - by Ela782
    The following code does not compile in VS2012, it gives error C2064: term does not evaluate to a function taking 1 arguments on the line of the second for_each (line 4 below). vector<string> v1; for_each(begin(v1), end(v1), [](string s1) { vector<string> v2; for_each(begin(v2), end(v2), [](string s2) { cout << "..."; }); }); I found some related stuff like http://connect.microsoft.com/VisualStudio/feedback/details/560907/capturing-variables-in-nested-lambdas which shows a bug (they are doing something different) but on the other hand that shows that what I print above should be possible. What's wrong with the above code?

    Read the article

  • VHDL Simulation Timing Behaviour

    - by chris
    I'm trying to write some VHDL code that simply feeds sequential bits from a std_logic_vector into a model of an FSM. However, the bits don't seem to be updating correctly. To try figure out the issue, I have the following code, where instead of getting a bit out of a vector, I'm just toggling the signal x (the same place I'd be getting a bit out). clk <= NOT clk after 10 ns; process(clk) begin if count = 8 then assert false report "Simulation ended" severity failure; elsif (clk = '1') then x <= test1(count); count <= count + 1; end if; end process; EDIT: It appears I was confused.I've put it back to trying to take bit by bit out of the vector. This is the output. I would have thought that on when count is 1, x would take on the value of test1(1) which is a 1.

    Read the article

  • What exactly is saved in SQL Server Statistics? When they get updated? Is SQL Server itself is taking care of them?

    - by Pritesh
    I have been working with SQL Server as a Developer a while. One thing I learnt is SQL Server manages Statistics which help Engine to create optimized execution plan. I could not figure out what exactly is stores in Statistics? (I read it saves Vector, but what Vector?) When/In which scenario SQL Server updates Statistics? How/why some time they go out of sync (old Statistics) In case of old Statistics is a manual DBA/Developer intervention is required or SQL Server Will get them updated. As a DBA/Developer how to find out if Statistics OLD? What should we do?

    Read the article

  • C++ struct sorting error

    - by Betamoo
    I am trying to sort a vector of custom struct in C++ struct Book{ public:int H,W,V,i; }; with a simple functor class CompareHeight { public: int operator() (Book lhs,Book rhs) { return lhs.H-rhs.H; } }; when trying : vector<Book> books(X); ..... sort(books.begin(),books.end(), CompareHeight()); it gives me exception "invalid operator <" What is the meaning of this error? Thanks

    Read the article

  • Java how to load modules

    - by gerardorn
    heres my problem: im building a server that loads modules. each module is a .jar file. inside the jar theres all the classes that the module need. the server needs to read the jar, find the main class (it doesnt have the main method on it is just the class that makes the module work but not as a different program), build an object of that class and store it in a vector of modules so that it can acces to a specific module depending on the job to be done. how can i do that? as far as the server, it is listening and reciving request, but thes no modules to delegate the job to, since my vector of modules is empty

    Read the article

  • C++ Euler-Problem 14 Program Freezing

    - by Tim
    I'm working on Euler Problem 14: http://projecteuler.net/index.php?section=problems&id=14 I figured the best way would be to create a vector of numbers that kept track of how big the series was for that number... for example from 5 there are 6 steps to 1, so if ever reach the number 5 in a series, I know I have 6 steps to go and I have no need to calculate those steps. With this idea I coded up the following: #include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { vector<int> sizes(1); sizes.push_back(1); sizes.push_back(2); int series, largest = 0, j; for (int i = 3; i <= 1000000; i++) { series = 0; j = i; while (j > (sizes.size()-1)) { if (j%2) { j=(3*j+1)/2; series+=2; } else { j=j/2; series++; } } series+=sizes[j]; sizes.push_back(series); if (series>largest) largest=series; cout << setw(7) << right << i << "::" << setw(5) << right << series << endl; } cout << largest << endl; return 0; } It seems to work relatively well for smaller numbers but this specific program stalls at the number 113382. Can anyone explain to me how I would go about figuring out why it freezes at this number? Is there some way I could modify my algorithim to be better? I realize that I am creating duplicates with the current way I'm doing it: for example, the series of 3 is 3,10,5,16,8,4,2,1. So I already figured out the sizes for 10,5,16,8,4,2,1 but I will duplicate those solutions later. Thanks for your help!

    Read the article

  • C++: Allocation of variables in a loop

    - by Rosarch
    Let's say I have a loop like this: vector<shared_ptr<someStruct>> vec; int i = 0; while (condition) { i++ shared_ptr<someStruct> sps(new someStruct()); WCHAR wchr[20]; memset(wchr, i, 20); sps->pwsz = wchr; vec.push_back(sps); } At the end of this loop, I see that for each sps element of the vector, sps->pwsz is the same. Is this because I'm passing a pointer to memory allocated in a loop, which is destructed after each iteration, and then refilling that same memory on the next iteration?

    Read the article

  • Do While loop breaks after incorrect input?

    - by Daminkz
    I am trying to have a loop continue to prompt the user for an option. When I get a string of characters instead of an int, the program loops indefinitely. I have tried setting the variable result to NULL, clearing the input stream, and have enclosed in try{}catch blocks (not in this example). Can anyone explain to me why this is? #include <iostream> #include <vector> #include <string> using namespace std; int menu(string question, vector<string> options) { int result; cout << question << endl; for(int i = 0; i < options.size(); i++) { cout << '[' << i << ']' << options[i] << endl; } bool ans = false; do { cin >> result; cin.ignore(1000, 10); if (result < options.size() ) { ans = true; } else { cout << "You must enter a valid option." << endl; result = NULL; ans = false; } } while(!ans); return result; } int main() { string menuQuestion = "Welcome to my game. What would you like to do?"; vector<string> mainMenu; mainMenu.push_back("Play Game"); mainMenu.push_back("Load Game"); mainMenu.push_back("About"); mainMenu.push_back("Exit"); int result = menu(menuQuestion, mainMenu); cout << "You entered: " << result << endl; return 0; }

    Read the article

  • C++ STL make_heap and pop_heap not working.

    - by Henrique
    I need to use a Heap, so i've searched about the STL one, but it doesn't seem to work, i wrote some code to explain what i mean: #include <stdio.h> #include <stdlib.h> #include <vector> #include <algorithm> struct data { int indice; int tamanho; }; bool comparator2(const data* a, const data* b) { return (a->tamanho < b->tamanho); } int main() { std::vector<data*> mesas; data x1, x2, x3, x4, x5; x1.indice = 1; x1.tamanho = 3; x2.indice = 2; x2.tamanho = 5; x3.indice = 3; x3.tamanho = 2; x4.indice = 4; x4.tamanho = 6; x5.indice = 5; x5.tamanho = 4; mesas.push_back(&x1); mesas.push_back(&x2); mesas.push_back(&x3); mesas.push_back(&x4); mesas.push_back(&x5); make_heap(mesas.begin(), mesas.end(), comparator2); for(int i = 0 ; i < 5 ; i++) { data* mesa = mesas.front(); pop_heap(mesas.begin(),mesas.end()); mesas.pop_back(); printf("%d, %d\n", mesa->indice, mesa->tamanho); } return 0; }; and this is what i get: 4, 6 2, 5 1, 3 3, 2 5, 4 So it's not working as a heap, as the maximum element on the vector is not being returned right. Or am i doing something wrong?

    Read the article

  • Call function from object instantiated in one class in another

    - by Dk43
    I have two classes, both of which need to be able to call the same instance of entitymanager class Engine { EntityManager::Entitymanager EManager; } And I need to add an object to a vector contained by this particular instance of Engine. What I want to do is be able to add a bullet spawned by the player to the vector that contains all my entities. class Player : Entity { void SpawnBullet() {Engine::EManager.Add(BULLET);} } The above returns this error: error: object missing in reference to ‘Engine::EManager’ How do I resolve this? Any help or pointers in the right direction would be much appreciated!

    Read the article

  • Doesn't Matlab optimize the following?

    - by kloop
    I have a very long vector 1xr v, and a very long vector w 1xs, and a matrix A rxs, which is sparse (but very big in dimensions). I was expecting the following to be optimized by Matlab so I won't run into trouble with memory: A./(v'*w) but it seems like Matlab is actually trying to generate the full v'*w matrix, because I am running into Out of memory issue. Is there a way to overcome this? Note that there is no need to calculate all v'*w because many values of A are 0. EDIT: If that were possible, one way to do it would be to do A(find(A)) ./ (v'*w)(find(A)); but you can't select a subset of a matrix (v'*w in this case) without first calculating it and putting it in a variable.

    Read the article

  • Declare variables that depend on unknown type in template functions.

    - by rem
    Suppose I'm writing a template function foo that has type parameter T. It gets an object of type T that must have method bar(). And inside foo I want to create a vector of objects of type returned by bar. In GNU C++ I can write something like that: template<typename T> void foo(T x) { std::vector<__typeof(x.bar())> v; v.push_back(x.bar()); v.push_back(x.bar()); v.push_back(x.bar()); std::cout << v.size() << std::endl; } How to do the same thing in Microsoft Visual C++? Is there some way to write this code that works in both GNU C++ and Visual C++?

    Read the article

  • Reading function pointer syntax

    - by bobobobo
    Everytime I look at a C function pointer, my eyes glaze over. I can't read them. From here, here are 2 examples of function pointer TYPEDEFS: typedef int (*AddFunc)(int,int); typedef void (*FunctionFunc)(); Now I'm used to something like: typedef vector<int> VectorOfInts ; Which I read as typedef vector<int> /* as */ VectorOfInts ; But I can't read the above 2 typedefs. The bracketing and the asterisk placement, it's just not logical. Why is the * beside the word AddFunc..?

    Read the article

  • Recursion: using values passed in parameters

    - by Tom Lilletveit
    I got this line of code that pops a int of the array saves it to int element then removes it from array. then in the return statement return CountCriticalVotes(rest, blockIndex + element); it ads it to the blockIndex variable and if it reaches 10 before the array is empty it returns 1. But my problem is this, I do not want it to add up all the values in the array in the parameter, but only add one then revert the parameter value back to it´s original state, then add a new, revert etc... How would i do this? int NumCriticalVotes :: CountCriticalVotes(Vector<int> & blocks, int blockIndex) { if (blockIndex >= 10) { return 1; } if (blocks.isEmpty()) { return 0; } else { int element = blocks.get(0); Vector<int> rest = blocks; rest.remove(0); return CountCriticalVotes(rest, blockIndex + element);

    Read the article

  • JTable.removeColumn() method throws exception

    - by sanjeev
    To hide a column from only the view of JTable, i am using the removeColumn() method. But it throws the exception Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 7 >= 7 at java.util.Vector.elementAt(Vector.java:470) at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:294) at javax.swing.plaf.basic.BasicTableHeaderUI.paint(BasicTableHeaderUI.java:648) i think, after removing column from the view, if i modified the model, then this exception pops out. is it because of there is no column in view, while the model is updating the table ? What is the best way to hide the column in view in JTable ? insteading of setting the sizes to 0.

    Read the article

< Previous Page | 51 52 53 54 55 56 57 58 59 60 61 62  | Next Page >