vectors of floats

M

mp

I am doing pairwise comparisons between 2 vectors of chars and
permuting one vector and storing the resulting calculations in a
vector<float> then I find a p-value among other stats. I have to do
1,000,000 permuations for each pair, with a total of 2000 pairs to
compare. Is a vector the appropriate container for such a job? Or is
this a newbie mistake?

Currently I am using a vector of pointers to an object which contains
my pair of vectors and other data members, including 3 vectors which
store 3 different stat calculations (added via push_back() ). This
seems to be a poor choice as my memory usage goes through the roof and
program crashes with more than 80 pairs to compare. I am a bit lost as
what to do? I am not even sure what questions to ask. any ideas would
be appreciated. Thanks, mp
 
V

Victor Bazarov

mp said:
I am doing pairwise comparisons between 2 vectors of chars and
permuting one vector and storing the resulting calculations in a
vector<float> then I find a p-value among other stats. I have to do
1,000,000 permuations for each pair, with a total of 2000 pairs to
compare. Is a vector the appropriate container for such a job? Or is
this a newbie mistake?

std::vector is the fastest when it comes to random access, and it's
probably the best container for what you need, if you never shrink
or grow it dynamically. If all you do is permutations (which simply
moves elements around using assignment) and comparisons, std::vector
is probably the best of all containers the Standard library has.
Currently I am using a vector of pointers to an object which contains
my pair of vectors and other data members, including 3 vectors which
store 3 different stat calculations (added via push_back() ). This
seems to be a poor choice as my memory usage goes through the roof and
program crashes with more than 80 pairs to compare.

That is in itself an empty statement. Why is memory usage so high?
Why does the program "crash"? Even if you use a lot of memory, your
program is not supposed to "crash" (I presume you mean "abnormally
terminate"). If one million permutations yields three million vectors
and then each grows dynamically and unpredictably, that might present
a challenge for your memory manager. However, there is always some
way to know how much to allocate. So, try using 'reserve' member
function to prevent the vectors from needing to reallocate. Your code
will get (a) faster and (b) less memory-demanding.
I am a bit lost
as what to do? I am not even sure what questions to ask. any ideas
would be appreciated. Thanks, mp

Read the FAQ 5.8.

V
 
D

Dave Townsend

mp said:
I am doing pairwise comparisons between 2 vectors of chars and
permuting one vector and storing the resulting calculations in a
vector<float> then I find a p-value among other stats. I have to do
1,000,000 permuations for each pair, with a total of 2000 pairs to
compare. Is a vector the appropriate container for such a job? Or is
this a newbie mistake?

Currently I am using a vector of pointers to an object which contains
my pair of vectors and other data members, including 3 vectors which
store 3 different stat calculations (added via push_back() ). This
seems to be a poor choice as my memory usage goes through the roof and
program crashes with more than 80 pairs to compare. I am a bit lost as
what to do? I am not even sure what questions to ask. any ideas would
be appreciated. Thanks, mp

You need to post some code so we can all fully understand your problem,
especially with regard to the memory usage "going through the roof" !
vector<> could well be the right structure to use, since if used
appropriately,
the accessing of elements can be virtually as efficient as using an array.
Again post some code, and we can review it and suggest approaches.

dave
 
M

mp

Dave said:
You need to post some code so we can all fully understand your problem,
especially with regard to the memory usage "going through the roof" !
vector<> could well be the right structure to use, since if used
appropriately,
the accessing of elements can be virtually as efficient as using an array.
Again post some code, and we can review it and suggest approaches.

dave


I seemed to have fixed my memory problem.

I start with initializing a pointer to an object,

Snpdata *q = NULL;

for(int i = 0; i< newVectorSize ; i++) //load vector with enough
pointers to my objects
{
q = new Snpdata();
vecSnpdata.push_back(q);
}


I then load the objects with data from a file and run my stat
functions.
At the end of this I just delete the object after writing the results
to a file.

delete vecSnpdata;

My program no longer aborts prematurely.
Thank you,

mp
 
B

BobR

mp wrote in message
I seemed to have fixed my memory problem.
I start with initializing a pointer to an object,

Snpdata *q = NULL;
for(int i = 0; i< newVectorSize ; i++) //load vector with enough
pointers to my objects
{
q = new Snpdata();
vecSnpdata.push_back(q);
}

You can eliminate the temp pointer [ Snpdata *q(0) ]:

for(int i(0); i< newVectorSize ; ++i){ // load vector with pointers to
objects
vecSnpdata.push_back( new Snpdata() );
} // for(i)
At the end of this I just delete the object after writing the results
to a file.
// >delete vecSnpdata;

delete vecSnpdata.at( i );
// use this, unless you are **positive** i is in range.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top