By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,385 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,385 IT Pros & Developers. It's quick & easy.

vectors of floats

P: n/a
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

Dec 27 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
mp wrote:
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
Dec 27 '05 #2

P: n/a

"mp" <mp****@wisc.edu> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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

Dec 28 '05 #3

P: n/a
mp
Dave Townsend wrote:
"mp" <mp****@wisc.edu> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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

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[i];

My program no longer aborts prematurely.
Thank you,

mp

Dec 28 '05 #4

P: n/a

mp wrote in message
<11**********************@z14g2000cwz.googlegroups .com>...

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[i];

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

--
Bob R
POVrookie
Dec 28 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.