|
I have 2 threads that are pulling different portions of the data set. I wanted to merge the data into a single place to make it easier to work with and it seemed like a good idea to copy the whole vector from ThreadA (it does most the work) then iterate it and match it against the data in ThreadB.
It may be easier to just break up the data and leave it in the threads.
Thanks for the reply,
- Rob
Whoever said nothing is impossible never tried slamming a revolving door!
|
|
|
|
|
You haven't to actually break the data: you may give to each thread a vector of pointers to the proper elements of the original vector.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
That sounds like an interesting solution, I may have to give that a go...
Thanks,
Rob
Whoever said nothing is impossible never tried slamming a revolving door!
|
|
|
|
|
RobJones wrote: I have 2 threads that are pulling different portions of the data set.
How about passing the thread an iterator pair (i.e. a range[^]) it can operate on. Just need to make sure the thread alters data in place and doesn't modify (i.e. add or delete elements) the vector.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
I'm performing printing of reports in an MFC app in what I think is a fairly canonical way...with a CDC and CFormView with OnDraw implemented. CDC's TextOut member functions and so on are called in OnDraw().
I get inconsistent results from printer model to printer model....The margins are different, and sometimes the important parts of my documents are actually cropped. Print preview accurately represents how the document will be (often incorrectly) printed.
Is there some technique that allows me to calculate an offset for the specific model of printer in use on the fly, to compensate when drawing in OnDraw() - perhaps something to do with CDC::GetDeviceCaps()? It seems that the area of the page that my reports are "projected onto" varies somewhat (not terribly, but certainly enough for it to be a problem), but the scale is always correct.
Thanks,
Sternocera
|
|
|
|
|
When I do this in VC++ 2005:
#include <list>
class Test
{
public:
template<class T>
Test(T *a, T *b)
{
}
};
int main(void)
{
std::list<int> integerList;
Test t(integerList.begin(), integerList.end());
return 0;
}
I get the following error:
error C2660: 'Test::Test' : function does not take 2 arguments
This is an example to show the problem, but my real goal is to have a templated constructor that takes two iterators and uses them to fill an internal collection. I don't want the constructor to depend on the iterator types, i.e. the constructor shouldn't care if the iterators are from a list, vector, or raw pointers to an array.
|
|
|
|
|
I'm not sure if this causes your problem or not, but as far as i know begin() and end() don't return pointers to iterators while your constructor takes two pointers. Test(T *a, T *b) .
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Code-o-mat wrote: I'm not sure if this causes your problem or not, but as far as i know begin() and end() don't return pointers to iterators while your constructor takes two pointers. Test(T *a, T *b).
Yup, that was exactly the problem. Thanks!
|
|
|
|
|
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
This fix the compiler errors
#include <stdio.h>
#include <list>
template <class T>
class Test
{
public:
Test(T a, T b)
{
}
};
int main(void)
{
std::list<int> integerList;
Test<std::list<int>::iterator> t(integerList.begin(), integerList.end());
return 0;
}
However, it is not what you're looking for, I suppose.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Alright, this is the thing... I have to create an Array for a number of objects in a setting with polymorphism.
Each object in the array needs to do the same thing... so I figure I can just create a loop for each item in an array.
Now, the method is called the same thing because of Polymorphism/inheritance
Although the method is placed somewhere else for each object...
so I have 10 classes.
the Base class is called: Animals
From Animals come: Marine, Reptiles, walkers
From there we have 6 different types of animals deriving from those.
#include "Gazelles.h"
#include "Goldfish.h"
#include "Sharks.h"
#include "Snakes.h"
#include <iostream>
using namespace std;
int main(int argc,char* argv[])
{
Animals *ourAnimals[6];
Animals *goldfish = new Goldfish();
Animals *crocodile = new Crocodiles();
Animals *elephant = new Elephants();
Animals *gazelles = new Gazelles();
Animals *shark = new Sharks();
Animals *snakes = new Snakes();
ourAnimals[0]=goldfish;
ourAnimals[1]=crocodile;
ourAnimals[2]=elephant;
ourAnimals[3]=gazelles;
ourAnimals[4]=shark;
ourAnimals[5]=snakes;
for(i=0;i<6;i++)
{
ourAnimals[i]
}
return 0;
}
each animal has converse, I am a bit of a noob with this obviously, so how do I get each object in the array to do what I want it to do?
|
|
|
|
|
Sivyo wrote: how do I get each object in the array to do what I want it to do?
How about something like:
Animal *ourAnimals[3];
ourAnimals[0] = new Goldfish();
ourAnimals[1] = new Crocodile();
ourAnimals[2] = new Elephant();
for (int i = 0; i < 3; i++)
ourAnimals[i]->converse();
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
yea, I did that right after I posted this... I should of figured, the complier didn't reconize the method from ctrl space so I thought it didn't work... but it did... problem solved...
Thanks for your ansswer, I am sure I will have more stupid questions soon
|
|
|
|
|
You should read about Virtual Functions & Polymorphism[^].
The converse() method must be virtual in your base class and you need appropriate implementation for this method in the derived classes.
Nuri Ismail
|
|
|
|
|
Not sure I really understood your question: you want all specific Animal do something specific in the converse method ? If that is the case, that is really simple: simply declare the function in the base class (Animal) as a virtual function and override it for each specific animal. Each specific animal can then do something specific.
|
|
|
|
|
Sivyo wrote: I am a bit of a noob with this obviously, so how do I get each object in the array to do what I want it to do?
Reading again the polymorphism chapter on your favourite C++ book may help, I guess.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi vc++ programmers,
i am doing an aplication in vs-2008 that is being migrated from vs-2003.I have 10 projects in my application.When i am building my application i am getting all my libraries getting created in release mode...
But when it comes to Debug mode for three projects library folders are not getting created...My application is working in the release mode but not in debug mode....
After compilation my linker->command line: is not showing those three libraries included in debug mode...
Why those three library files are not getting created? please show me any remedy!
Thanks in advance...
|
|
|
|
|
Vetukuri Raju wrote: When i am building my application i am getting all my libraries getting created in release mode...
But when it comes to Debug mode for three projects library folders are not getting created...
This would indicate that there are differences in the debug/release settings, either for the entire application or those three projects.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
hi thanks for the reply...
I checked for all the differences,and checking with 2003vs settings also..but this didnt worked..Migration from 2003 makes any problem?
and can you help further?
|
|
|
|
|
Vetukuri Raju wrote: Migration from 2003 makes any problem?
I can't imagine so given that 70% of your library files are being created.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi they are getting created now,,but those three libraries are not getting linked.but they are getting linked in release mode...
I am not getting those three libraries in my linker->commandline even though i have given those libraries from projectsettings->linker->additional dependencies...
|
|
|
|
|
Hi,
While reading the double value from the written text file, the memory get corrupetd.Here is the sample code and its output for the scenario. Can anyone help in this.
#include <stdio.h>;
#include "stdafx.h"
int main(int argc, char* argv[])
{
double dbleArray[][4] = { -315.00000255999998,0.00000000000000000,0.00000000000000000,-166.19238000000001,
-329.19238000000001,315.00000255999998,-329.19238000000001,-329.19238000000001,
0.00000000000000000,0.00000000000000000,320.00000000000000,-536.00000000000000,
0.00000000000000000,0.00000000000000000,0.00000000000000000,1.0000000000000000};
FILE* pFile = NULL;
pFile = _wfopen(L"C:\\Temp\\InputVolumeDetails.txt", L"w");
if(pFile)
{
for(int nRow=0; nRow<4; nRow++)
{
for(int nCol=0; nCol<4; nCol++)
{
fwrite(&dbleArray[nRow][nCol], sizeof(double), 1, pFile);
}
}
}
fclose(pFile);
double dbleArray_r[4][4];
FILE* pFile_r = NULL;
pFile_r = _wfopen(L"C:\\Temp\\InputVolumeDetails.txt", L"r");
if(pFile_r)
{
for(int nRow=0; nRow<4; nRow++)
{
for(int nCol=0; nCol<4; nCol++)
{
fread(&dbleArray_r[nRow][nCol], sizeof(double), 1, pFile_r);
printf("%f\n",dbleArray_r[nRow][nCol]);
}
}
}
fclose(pFile);
return 0;
}
The output for the above code is
-315.000003
0.000000
0.000000
-92559631348757048000000000000000000000000000000000000000000000.000000
-92559631349317831000000000000000000000000000000000000000000000.000000
-92559631349317831000000000000000000000000000000000000000000000.000000
-92559631349317831000000000000000000000000000000000000000000000.000000
-92559631349317831000000000000000000000000000000000000000000000.000000
-92559631349317831000000000000000000000000000000000000000000000.000000
-92559631349317831000000000000000000000000000000000000000000000.000000
-92559631349317831000000000000000000000000000000000000000000000.000000
-92559631349317831000000000000000000000000000000000000000000000.000000
-92559631349317831000000000000000000000000000000000000000000000.000000
-92559631349317831000000000000000000000000000000000000000000000.000000
-92559631349317831000000000000000000000000000000000000000000000.000000
-92559631349317831000000000000000000000000000000000000000000000.000000
|
|
|
|
|
Try to change write and read modes to binary L"wb" and L"rb"
|
|
|
|
|
A very subtle situation which is a great lesson for the future. Both your read and write loops contain no error checking. However having completed the write processing, a visual check of the output file suggests that the content is correct. The read loop reads sixteen values and prints them out, but does not check that you have read the full values every time. If you take a look at the file produced by this program you will see the hex value 'x1a' at character position 26. This character is taken by the fread() function as signifying no more data, so the last value read in is incomplete which gives the strange value printed by the program. Every subsequent read will fail so the value stored in memory is whatever was there previously; in this case the values that happen to be in the array storage space. The solution is to always check the results of your read and write statements, but in this case you also need to use "wb" and "rb" on your _wfopen statements to ensure the 'x1A' is not taken as end of file.
|
|
|
|
|
Thanks for all your replies.
I tried with "wb" and "rb" mode and its working fine.
|
|
|
|