C++ :: Faster To Create New Variable Or Reuse Existing One For Math Calculation?

Feb 15, 2015

is it better to reuse an existing variable or create a new variable for the following situation:

/* Is this faster: */
glm::mat4 newViewModelMatrix = (*existingViewMatrix) * (*existingModelMatrix);
/* Or is this faster? */
glm::mat4 existingViewModelMatrix; /* declared in class header - initial value assigned in class constructor */
existingViewModelMatrix = (*existingViewMatrix) * (*existingModelMatrix);

Just wondering if it makes a difference or not.

View 1 Replies


ADVERTISEMENT

C/C++ :: How To Reuse Existing Code To Read Data File In Qt

Aug 13, 2014

I've got some code in C++ that does some basic analysis on price data and I run it from the cmd prompt. One of the functions I had built to read in the data is as follows:

void ReadPricesFromFile(constchar*filename,std::vector<PriceInfo>&prices)
{std::ifstreaminput(filename);
input>>prices;}

How would one merge this type of code into a Qt GUI? Ideally, I'd like to use something like QFileDialog to open up a folder with my data files, select a file, and then read the file that the user selects. Would the main.cpp look something like this?

int main (int argc, char *argv []) {
QApplication prog (argc, argv);
QPushButton *load_button = new QPushbutton ("Load File");
QObject:: connect (load_button, SIGNAL (clicked()), &prog, SLOT ( (ReadPricesfromFile function?);
load_button-> show ();
return prog.exec ();}

View 3 Replies View Related

C :: Reaction Game - How To Create Randomize Algorithm Which Gets Exponentially Faster

Mar 29, 2014

I am creating a reaction game using a series of lasers and LRDs and need to make a function which waits for a specific pin in portb to be triggered high before it can move onto waiting for the next pin to be triggered. The time lasped before the "game loses" needs to get exponentially faster as the game goes on.

I am using statements such as if(input(PIN_B0)==1 generate_tone(G_note[2], 1000); but unsure how to write in c "wait x amount of time, if trigger move onto next random pin or no trigger go to lose function.

View 8 Replies View Related

C++ :: Comparing Math Operator With A Variable?

Oct 14, 2013

I am trying to compare a math operator with a variable, but i keep getting this error:

postfixDriver.cpp:93: error: expected primary-expression before ')' token.

I'm sure it's probably something simple, but im just not seeing it. Here is the code snippet:

while (strlen(str) != 0) {
split (str, token);
Postfix stack;
double a;
double b;
double answer;
if (atof(token)==0.0)

[Code] .....

View 2 Replies View Related

C/C++ :: Define Math Operators As Variable?

Aug 17, 2014

I have to create a program that read two numbers and the math operators +, -, * and /. After that I should print the operation required. But I tried to declare a <symbol> variable as char type, without sucess...

Here goes my script:
float num1, num2, result;
char symbol;
printf("Write two numbers:
");

[code]....

View 1 Replies View Related

Visual C++ :: Create A Program That Perform Same Calculation For Every Oscillation

Jan 17, 2014

I am reading from a text file and want to create a program that will perform the same calculation for every oscillation.

The text file I'm reading from is attached to this post. A3.txt

The program that I've written is as follows:

Code:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile ("AP1.txt");
ofstream results_file ("APDuration.txt");

[Code]...

Where I'm having trouble is in having the inFile.seekg function iterate to the next series of values.

Here is what the data file looks like in a graph:

In a nutshell, my program will read the duration of each action potential from a point called "dVmax" (where the upstroke is at its maximum upward rate of change) to the point of 90% repolarization (on the downstroke where 90% of the total wave amplitude is subtracted from the volts at peak amplitude).

If you would like to test my program on one action potential, here is one action potential : AP1.txt

View 8 Replies View Related

C++ :: Take Values From Text File And Store Them In Variable And Use For Later Calculation

Nov 8, 2013

I have a text file in the form

5502 5202.3
1523 2536.1
1254 1256.2
17846 8956.2 and so on

left one is time and right one is pressure, I need to show the time value as it is but i need to use the pressure value to calculate air speed. I don't know how to use the strings to pick up the list properly. I did the calculation formula for the air speed but i can't pick the pressure value up from the text file. here's what i did:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code].....

View 3 Replies View Related

C# :: How To Reuse Event

Apr 14, 2014

I am creating one c# project. In this project I have one mdi form and many child forms.

All the child forms contains one panel named as panel1.

Now when child form opens i use the following code in all child form all child forms' load event contains the following line.

this.WindowState = FormWindowState.Maximized;

and all child forms' resize event contains the following line.

panel1.Left = (this.ClientSize.Width - panel1.Width) / 2;
panel1.Top = (this.ClientSize.Height - panel1.Height) / 2;

so my question is if possible that the above code i write only once so i donot write this code in all the child forms load and resize event.

View 2 Replies View Related

C++ :: Faster Prime Number Algorithm

Oct 19, 2014

Can I possibly get a better implementation of a prime number detecting algorithm than the one I already have below?

Code:
#include <cstdio>
#include <cstdlib>
int main() {
int no, high, low;
int divisor;

[Code] .....

View 8 Replies View Related

C++ :: How To Reuse Memory Previously Allocated

Dec 14, 2013

I have a question about memory allocation.I have a function that calls a lot of object constructors, which in return these constructors will allocate a lot of memory.Now, in my program I am sure that if I first call this function , say it will call the constructor of 100 object.If I call this function again and again, I am sure that it will only call the constructor 100 times again, and thus I am sure that the memory allocated in the first call can be reused again.

How can I reuse the memory allocated in the first call?Can I use something like boost:object_pool so that I can tell the pool to restart from the begining and do not allocate extra memory, just use what you already have?

View 6 Replies View Related

C++ :: Vector Like Container Which Can Reuse Space?

Dec 24, 2014

Unoptimized problem: I work on a table (vector of vectors). vector< vector<double> >

Optimization: If the current set of vectors is v1...vn (so each vk is a vector of double), my problem is such that I will only work on the last M of the vectors, the earlier vectors are irrelevant. I would like to reuse space to make the algorithm scalable, so I want to delete the vectors that can be forgotten. I read in a new vector, I delete the oldest vector.

View 2 Replies View Related

C/C++ :: OpenMP Can Make For Loop Faster?

Dec 9, 2014

I'm trying to optimize this code using openMP. The line I added made it run about twice as fast but I'm trying to figure out how to make it even faster. Could reshaping the loops potentially increase the speed?

//4 threads
int listsize=15000;
#pragma omp parallel for shared(f) private(i,j,hash)
for(i = 0; i < listsize; i++) {
printf("Thread: %d i: %zu wl_size: %zu
",omp_get_thread_num(),i,wl_size);
for (j = 0; j < num; j++) {
h = f[j] (getw(list, i));
c[h] = 1;
} }

View 2 Replies View Related

C++ :: Reading Data From File Then Storing It To Reuse?

Mar 27, 2013

Im tasked with reading a data file, this is an example snippet

list of trophy winners
year facup leaguecup 1stdiv 2ndiv
1960/61 Tottenham Hotspur Aston Villa Tottenham Hotspur Ipswich Town
1961/62 Tottenham Hotspur Norwich City Ipswich Town Liverpool
1962/63 Manchester Utd Birmingham City Everton Stoke City

The file starts in 1892 and is up to 2011/12, there is data missing for some years due to the wars etc,

once ive read the file, i need to store the data, for me to re-use.

There are a lot of useful link regarding reading data in, but they tend to be with very small files with say 10 lines of numbers.

View 1 Replies View Related

C :: Cache Optimizations / Make Multiplication And Calculations Faster?

Jan 30, 2014

I have a 125X125 array, each element is 55 bits. The cache line for the CPU ( Cortex A9) is 32 bits. Is there anyway to do optimizations, like loop tiling that would make multiplication and calculations faster?

View 5 Replies View Related

C++ :: Analysis Of Discrete Wavelet Transform - Modifying For Loop To Make It Faster

Aug 25, 2014

I have this code which performs the analysis part of discrete wavelet transform. It works pretty well. However, I wish to reduce the time that it consumes even further. I did use reserve() and it worked upto few msec.

int rows = signal.size();
int cols = signal[0].size();
int cols_lp1 =(int) ceil( (double) cols / 2);
vector<vector<double> > lp_dn1(rows, vector<double>(cols_lp1));
vector<double> temp_row;
temp_row.reserve(512);

[Code] ....

View 5 Replies View Related

C/C++ :: Create Local Instances Of A Global Variable?

Oct 4, 2012

is it possible to have a global variable pointing to a different address depending on the thread?

Imagine one would like to use threads with the loop:

for (i=0;i<n;i++){
globalPointerVariable=getAddress(i);
DoThingsUsingThe_globalPointerVariable();
}

View 4 Replies View Related

C++ :: Create 1 Variable That Accept Any Type Of Values?

Aug 24, 2013

Can I create 1 variable that accept any type? And can I give it the NULL value too?

View 14 Replies View Related

C++ :: Create A Loop To Return Minimum Value Using Boolean Variable

Mar 20, 2013

I need to create a loop to return a minimum value using a boolean variable but don't quite understand how to format my algorithm.

#include <iostream>
using namespace std;
int main() {
bool first = true;
while (first) {
cout << "Enter a number (X to exit): ";
int num;

[Code]....

I know its jacked up any comments in the code would be great I need to finish the program but also understand it.

View 6 Replies View Related

C++ :: Create Assignment Operator For A Class That Uses Pointer For Its Private Variable?

Mar 30, 2013

i am trying to create the assignment operator for a class that uses a pointer for it's private variable. The error is saying expected constructor, deconstructor, or type conversion before "operator. (which is the assignment operator. I have tried everything i could think of or find online and nothing has worked. below is the code for the assignment operator in the .h file and the .cpp file.

//Assignment constructor
indexList &operator=(const indexList <T> &rhs);
template <class T>
indexList<T>::indexList operator=(const indexList <T> &rhs) {
if(this != &rhs) {
numberOfElements = rhs.numberOfElements;

[Code]...

View 1 Replies View Related

C :: Create Program That Takes In Information And Formats It Into 3 Columns - Float Variable Not Working

Dec 12, 2013

Here your supposed to create a program that takes in information and formats it into three columns.

I can't seem to use the float variable unitprice with decimal places here for, if I try to use %.1f and type in an input, the program seems to skip over the second scanf function, not allowing me to put input into the third scanf function as the program runs before I can.

I can use %f on its own and it works but this creates too many zeroes(and you're supposed to set the currency limit to $99999.99).

Code:
#include <stdio.h>
int main(void) {
int itemno, month, year, day;
float unitprice;

[Code]....

So the output should look like three columns. It's just the float that is the issue here....

View 5 Replies View Related

C/C++ :: Reading From Existing File Name?

Aug 5, 2014

#include <iostream>
#include<fstream>
using namespace std;
int main() {
string choice, meaning, word, yesOrno;
char add[20];

[code]....

i have done my best but i have still problem with searching words from previously saved words from user this code it keeps adding but it won't display when i search for.

View 10 Replies View Related

C# :: How To Edit Existing XML File

Jul 6, 2014

I'm trying to edit an existing xml file but with no luck. I'm new to xml environment.

This is the xml content :

<?xml version="1.0" encoding="UTF-8"?>
-<mmp>
<ID>aaa</ID>
<clientID>bbb</clientID>
<time>2004-05-10T17:35:41.29</time>
<session>2000</session>
<Answer>Yes</Answer>
-<Program>
<_id>ppp</id>
</mmp>

I'm trying to change the time and id values and can't do it.I tried almost anything.

View 4 Replies View Related

C :: Encode/ Decode Existing EXE File

Dec 28, 2014

Let's say I have an exe-file (for example computer game) and need to forbid to run it until certain date or time during the day. Any 'manipulations' with file are allowed. offer me a simple way of how to encode/decode such a file?

View 7 Replies View Related

C++ :: Modifying Existing Array With A Function

Mar 26, 2013

I have an array of char representing pixels in a bitmap, which I want to modify. I don't think I can just iterate over the array and pass chars into a function individually, because the function needs to take into account the neighboring pixels, too.

I thought of two ways to do this. The first would be to pass the array to the function as an argument, then have the function change it and return it. The trouble is I'm not exactly sure what happens internally when you pass an array to a function and return it. Is it the same array, modified? Or is it a copy of the array, so now you're using twice as much memory?

Alternatively I guess I could have a function with a void return type and pass a pointer to the array. I'm somewhat new to this, but the way I understand it is that a pointer is like the address of a house, while the array is the actual house. So if I give the function the address, it can go to that address and rearrange the furniture inside the house. Then, after the function returns, I can go to that address myself and see all the rearranged furniture, even though the function has already returned.

Is there a problem with the second way? It seems a bit neater, but maybe I'm understanding pointers wrong.

View 14 Replies View Related

C++ :: Existing Code For String To Expression?

Apr 17, 2012

I would like to get hold of the code for a function that takes a string as input argument and returns a numerical value, either integer or double, according to the the expression represented by the string. For example the string may look like this:

Code:
"(256 * d3 + d4) * factor - offset"

then the function would calculate the value of

Code:
(256 * d[3] + d[4]) * factor - offset

where d is an integer array, factor and offset are double or int variables or constants. For my application the name for the array can be fixed to be "d", and the names for other variables and constants are known. The closest thing I could find on-line is this:

[URL]

which only does literal integer calculations, no double, no variables or constants. Are there existing code that does what I need or do I have to write my own?

View 2 Replies View Related

C Sharp :: Add Column To Existing MS Database Permanently?

Oct 5, 2013

adding a column in ms access database and update it with a value.Here is my code, it gives an error that says syntax error in field definition.

string myConn = " ";  
myConn = "Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=C:/Users/EmployeeAttendanceRegister/EmployeeAttendanceRegister.accdb";  
OleDbConnection myCon = new OleDbConnection(myConn);  
string myInsert = "ALTER TABLE Attendance ADD COLUMN SignIn" + dateTimePicker1.Value;  

[Code] .....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved