473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

vectors of floats

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
4 2132
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

"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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Pratyush | last post by:
Hi, Suppose there is a vector of objects of class A, i.e., std::vector<A> vec_A(N); The class A satisifies all the STL vector requirements. Now I wish to add some attributes for each of the...
9
by: Nancy Keuss | last post by:
Hi, I've created a vector of vectors of ints, and I want to pass it as a parameter to a function. Is this possible, and if so, then what is the syntax like for the function header and function...
5
by: Computer Whizz | last post by:
I was reading through Accelerated C++ at work when I read through the first mention of Vectors, giving us certain functions etc. Is there any benefit of Arrays over Vectors? Since all Vectors...
3
by: Amit | last post by:
Hello. I am having some problem organizing a set of vectors. The vectors itself, could contain a pointer( say integer pointer) or could contain another object MyClass. 1>So, first of all, is...
4
by: Dr. J.K. Becker | last post by:
Hi all, I have vectors that holds pointers to other vectors, like so: vector<whatever> x; vector<whatever*> z; z=&x; Now I add something to x
5
by: madhu | last post by:
http://msdn2.microsoft.com/en-us/library/fs5a18ce(VS.80).aspx vector <intv1; v1.push_back( 10 ); //adds 10 to the tail v1.push_back( 20 ); //adds 20 to the tail cout << "The size of v1 is " <<...
2
by: wuzertheloser | last post by:
Use the program skeleton below (starting with #include <stdio.h>) as the starting point for quiz4. Add the necessary code to the functions prob1() and prob2(), and add the other 2 functions, as...
16
by: luca bertini | last post by:
Hi, i have strings which look like money values (ie 34.45) is there a way to convert them into float variables? everytime i try I get this error: "numb = float(my_line) ValueError: empty string...
1
by: Rob | last post by:
How would I do this? I want to be able to handle vectors of many different types of data and vectors that can contain any number of other vectors of data. Currently, I have a templated...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.